Trending November 2023 # How List Function Works In Php # Suggested December 2023 # Top 17 Popular

You are reading the article How List Function Works In Php updated in November 2023 on the website Moimoishop.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 How List Function Works In Php

Introduction to PHP list

PHP list function is an important function used for assigning values to a list of variables while performing single operation at one go. This function is not present in all the PHP versions and is introduced exclusively in PHP versions before 7.1 which works only for numerical arrays while assigning values to the list of variables. The values assigned to the variables is the return type once executed with the help of PHP list function. PHP list function is not actually a function like array rather it is considered a language construct for assigning values.

Start Your Free Software Development Course

Syntax

list(var_1, var_2, ...)

The syntax flow is in a way where there is a list as function comprising of arguments passed from the function:

list: The function list() is declared.

var_1: The variable passed as an argument is required and is quite of mandatory in the sense this acts as the first variable to assign a value to the variable declared.

var_2: The second variable is optional and then this variable is used to assign values to the list followed by sequence.

This syntax when applied has a return type as assigned array which means whatever values are assigned to the array is the return type for that instance.

How list Function works in PHP?

list() function is an inbuild function in PHP which is exclusively used for assigning values to more than one variable by performing a single operation at the time of execution.

Let’s see the actual flow for working of list function in PHP which is described as follows :

Initially list being an inbuild function doesn’t required to be written and doesn’t require any external function call it works just seamlessly without much intrusion.

The array gets assigned with the required values from the multiple values considered at the time of execution.

There is a misconception regarding the array declared as a variable for assigning values but it’s just a myth in actual it is just a language construct.

Everything gets executed in a single operation using list() function while assigning variable.

This function works seamlessly on the numerical arrays only, which represents the fact that the user will get interacted with the arrays using first variable which is var_1.

The second argument getting passed to the function is an optional argument which gets retrieved and worked once the first argument satisfies the condition.

One point needs to be kept in mind which is like the number of variables should not exceed length of the numerical array and in case it exceeds the array defined variable then it will give error with parameters types and there will be no return type at the time of execution.

There should be no exception introduced while executing this list function otherwise the requirement and the return type will not get suffice.

If a function is not having any return statement, then implicitly it will return NULL as its return type at the time of execution.

The parameters to be passed as part of the function should be arranged in a way where the list of variables will get separated by spaces within the code.

The first variable to be passed from the function is a mandatory variable for the return type.

Another important point to look upon is the version compatibility which means that the PHP version should have version support less than 7.

Also, coming to the version compatibility for PHP then PHP version 5 in the list should assign values starting with right most parameter.

Whereas there is a difference with PHP version 7 where the assignment to the values of variable which will appear as left-most parameter.

In case normal variables are used then there is no need to worry about assigning values to the variables and then using these arrays with indices is used for arranging the values in an order.

But in case of order must be maintained like from left to right or from right to left then it is very much need to keep in mind about the PHP versioning.

Examples of PHP list

Given below are the examples of PHP list:

Example #1

This program demonstrates the PHP list where the array is assigned with the variable having values as shown in the output.

Code:

<?php $an_arr = array(“Banana”,”Mango”,”Apple”); list($a_1, $b_2, $c_3) = $an_arr; echo “I have many fruits, one $a_1, one $b_2 and one $c_3.”;

Output:

Example #2

This program demonstrates the PHP list where array is assigned with the first and third value within the variable as shown in the output.

Code:

<?php $arr_b = array(“Pencil”,”Copy”,”Pen”); list($k_0, , $z_1) = $arr_b; echo “Used_variable_for_modification $k_0 and $z_1 variables.”;

Output:

Example #3

This program demonstrates the declaration of array in a way where initially all the variables are listed, followed by retrieving some values and then listing some of them among all from which the third one gets skipped in case of the list with all the string it will return the NULL value as shown in the output.

Code:

<?php $in_p = array(‘choco’, ‘caramel’, ‘pancake’); list($choco, $cake, $caramel) = $in_p; echo “$choco cake $color and $caramel appears relishing n”; list( , , $caramel) = $in_p; echo “caramel cake tastes wow $caramel!n”; list($choco, , $cake) = $in_p; echo “$choco has $cake.n”; list($gi_t) = “lost_in n”; list($choco, , $cake) = $in_p; echo “$choco has $cake.n”; var_dump($gi_t);

Example #4

This program demonstrates the nested array by using list function as shown in the output.

Code:

<?php list($a_1, list($b_2, $c_0)) = array(1, array(4, 6)); var_dump($a_1, $b_2, $c_0); echo “listing of nested array”;

Output:

Conclusion

PHP list is an inbuild function which gives user the flexibility and versatility to adapt this function as part of the implementation as per requirement. Use of PHP list make the values arranged in some order which gives user visibility to implement a user-friendly array return values with variables.

Recommended Articles

This is a guide to PHP list. Here we discuss the introduction, how list function works in PHP? along with examples respectively. You may also have a look at the following articles to learn more –

You're reading How List Function Works In Php

How Recover() Function Works In Go Language?

Introduction to Golang recover()

Web development, programming languages, Software testing & others

Syntax:

In the below syntax we are showing a simple syntax for the recovery function of the go language, we see the below syntax attribute with the following steps.

Here error is the dynamic variable you can create with any other name according to your wish.

Recovery is a function which will handle the case of error.

We can use the panic function to display the error in the customized format.

if error := recover(); error != nil How recover() Function works in Go Language?

Before seeing the work of the recovery in go language we need to know why we need recovery, if you have seen any other programming language like java and dot net they have try and catch statement which deal with situation which is not in our hand, for example in case if we are performing division and by some way division become like number / 0 which means the output will be infinite and our system can go into blocking stage as they will not be able to handle infinite so for such type of situations we use the recovery.

Working of the recovery in the following steps:

Recovery is a function which is used inside the deferred type of function, it is not meant for use in the case of any normal function.

In case if we want to handle an error case and we are using recovery and it is not inside the deferred then it will not be able to sequences of panicking.

We have to write a function inside the import of the go language and inside this function we need to write the capturing of the exception logic.

Remember the recovery function in the go language is the inbuilt function.

Examples of Golang recover()

Given below are some of the examples which display the working of the recovery function, to execute these examples we can create a file with name chúng tôi and we can execute the file after copy pasting of the below examples. We can use the command go run chúng tôi and we will get the output.

Example #1

Below is an example where we are dealing with the panic condition without using defer, and you can see the output which totally looks like an error.

package main import "fmt" func exceptionCase() { if e := recover(); e != nil { fmt.Println("Handling the exception and exception is ", e) } } func start(school *string, school_name *string) { exceptionCase() if school == nil { panic("Error: The value of school can not be nil") } if school_name == nil { panic("Error: The school name can not be nil") } fmt.Printf("The school type is: %s n The school name is: %sn", *school_name, *school_name) fmt.Printf("Here we are returning response of success from the start function") } func main() { school_type := "Private School" start(&school_type, nil) fmt.Printf("Here we are returning the response from the main function") }

Output:

Example #2

Here we are using the recovery function along with defer and you can see the screen output, it is more understandable in nature.

Code:

package main import "fmt" func exceptionCase() { if e := recover(); e != nil { fmt.Println("Handling the exception and exception is ", e) } } func start(student_type *string, student_name *string) { defer exceptionCase() if student_type == nil { panic("Error: The value of school can not be nil") } if student_name == nil { panic("Error: The school name can not be nil") } fmt.Printf("The Student Type: %s n The student name: %sn", *student_type, *student_name) fmt.Printf("Here we are returning response of success from the start function") } func main() { student_type := "Regular Student" start(&student_type, nil) fmt.Printf("Here we are returning the response from the main function") }

Output:

Example #3

In the below example we have taken some calls test1 and test2 and used the deferred, here we are using the function recovery inside the recovery and it will be used to handle panic cases.

Code:

package main import ( "fmt" "time" ) func exceptionCase() { if e := recover(); e != nil { fmt.Println("Exception case is", e) } } func test1() { defer exceptionCase() fmt.Println("Let us greet the function test1") go test2() time.Sleep(11 * time.Second) } func test2() { fmt.Println("Let us greet the function test2") panic("Do not worry!!") } func main() { test1() fmt.Println("Here we are returning final response of main") }

Output

Recommended Articles

This is a guide to Golang recover(). Here we discuss the introduction, syntax, and working of the recover() function in the go language along with examples and code implementation. You may also have a look at the following articles to learn more –

Types Of Error In Php

Introduction to Error in PHP

The event of the occurrence of deviation of the result from the accurate result is termed as an Error. In PHP, error can be generated because of the usage of an incorrect format of coding or implementation of non-feasible functionality. Based on the root cause and level of severity, errors in PHP are categorized in 4 types, such as:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax error (Parse error)

Warning Error

Notice error

Fatal error

Types of Errors in PHP

Lets discuss the Types of Error in PHP.

1. Syntax Error (Parse Error)

In PHP, the scripting needs to follow standard grammar to develop an executable code. When the written code syntax gets deviated from the standard, syntax error takes place. It is also called as parse error. This error gets checked in the compilation stage itself and execution of the code gets stopped. It does not allow the execution unless the error is not fixed and compilation is completed without any syntax flaw. The error constant that is used to represent compile time parse (syntax) error: E_PARSE

Example:

The below code snippet is developed to assign values to PHP variables and display the stores values on the output window.

<?php $Correct_Var = "Writing a code to demonstrate Syntax(Parse Error)"; Incorrect_Var = "The '$' symbol is missing for variable y!!!"; echo $Correct_Var; echo Incorrect_Var;

Output:

PHP compiler understand existence of any variable when a string is associated with $ symbol. In the above code, definition of variable Incorrect_Var does not satisfy the grammar, hence the compiler throws syntax error for the code and execution is interrupted.

2. Warning Error

This error arises when the PHP script is trying to process any invalid information such as trying to perform a file operation on a file which does not exist or try to call a function with number of input values i.e. different from number of arguments present in the calling function definition. These are serious errors but does not stop the execution of the program and ends in exhibiting unexpected result. The error constant that is used to represent run time warning without terminating script execution: E_WARNING

Example:

The below code snippet is written to call another script file within the current programming.

<?php echo "Beginning of program execution"; $Correct_Var = "Writing a code to demonstrate Warning Error"; echo $Correct_Var; include ("MissingScript.php"); echo "Ending of program execution";

Output:

According to the programming, compiler successfully compiled to code and starts execution. The execution continues sequentially. For the command include (“MissingScript.php”), it is looking for the script in the default path …/usr/share/php and does not found any script with the given name. Thus it ends in resulting the warning message for that specific command and execution the rest of the code as designed.

3. Notice Error

Example:

<?php echo "Beginning of program execution"; $Correct_Var = "Writing a code to demonstrate Notice Error"; echo $InCorrect_Var; echo "Ending of program execution";

Output:

The compiler does not recognize the variable $InCorrect_Var as it is not defined in the code. Hence it throws the Notice error.

4. Fatal Error

A compile time error that is encountered due to any invalid command such as missing of function definition for a calling function, is coined as fatal error. Severity level of this type of error is critical and hence it does not let the execution to be proceed and throw fatal error message as output. The error constant that is used to represent the fatal error which triggers script termination: E_ERROR

Example:

The below code snippet is designed to call demonstrate application of function in PHP scripting.

<?php echo "Beginning of program execution"; $Correct_Var = "Writing a code to demonstrate Fatal Error"; echo $Correct_Var; UndefinedFunction();//Calling a function which is not defined in the script echo "Ending of program execution";

Output:

Additional Note

1. Error handling is easy in PHP. If any developer does not have access to the complete code for any application, it is recommended to use error handling functions in possible scenarios.

2. In order to avoid new error in the PHP programming, developer is expected to follow proper coding guidelines and stays alert towards probabilities of various types of errors, warnings and notices.

3. It is recommended not to allow any error or warning or notice to be displayed to the user. Hence the best practice for any safe PHP programming to ensure the required configuration to be available in chúng tôi file.

The desired value for the below variables are:

error_reporting as ' E_ALL' display_errors as 'Off' log_errors as 'On'

The below code can be included in any PHP script to configure the desired values in the chúng tôi file:

error_reporting(E_ALL); ini_set('display_errors','0'); ini_set('log_errors','1');

This function needs to be designed with some specific guidelines as follows:

Function should be capable of handling minimum of two input parameters: error message and error level and maximum of 5 input parameters by including the optional parameters such as line number, file and error context.

Recommended Articles

This is a guide to Types of Error in PHP. Here we discuss the introduction and 4 types of errors in PHP along with different examples and code implementation. you may also have a look at the following articles to learn more –

How Recursion Works In Prolog?

Introduction to Prolog Recursion

The prolog recursion is defined as, in prolog, the recursion seems when a predicate has some goal which referred to itself, the recursion is a function that can call itself until the goal succeeds, the predicates in prolog recursion are recursively defined because it has more than one rule in defining to refer itself, recursion is a powerful tool and it is widely used in prolog, it can also be used by many different data structures where the structures include sub-structures, it has two components one is base recursion and another is recursion itself, it mainly involves the predicates to calling itself, so prolog supports recursion.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The syntax of recursion by using the family relationship:

predecessor(M,O) :- parent(M,N),predecessor(N,O).

So, the first line as the parent(M, O) has some facts given from there it will get instantiated, which is also called a base case, the second line shows the recursive relationship.

The clauses are divided into facts and rules.

Facts: The clauses without a body is called facts,

Syntax:

parent(M,O).

Which can be equivalent to-

parent(M,O):- true.

Rule: The rule is a type of form, it has been used to call the predicates and as we know the predicates are in-built in prolog.

For example, we have the clause that ‘Brain:- Heart.’, so it means ‘Brain is true if Heart is true’.

How Recursion Works in Prolog?

The recursion is a very powerful tool in prolog, recursion is used by many programming languages. So we wish to perform some operations either over data structure or until a certain point to be reached, in prolog this repetition is called recursion. It can also be used by many data structures so recursive data structure is the one where the structures include the sub-structures whose function is the same as that of the whole structure.

The predicate we are using in recursion is recursive in nature. We will see the working of recursion with the help of one example,

Example:

is_eating(S, T):- just_cook(S, T). is_eating(S, T):- just_cook(S, R),is_eating(R, T).

Let us see the working of recursion in family relationship, so we know that what is recursion, recursion is having mainly two issues, first is that for starting inputs and outputs are known to us so it is known as base case recursion, in prolog it will be satisfied by the given facts and another issue is that a prolog program or the prolog function can call itself, so we will see when the prolog calling itself in its declaration, so this can also a good example of recursion. So in other programming languages, we might have used recursion and prolog supports recursion and here in a family relationship, we can use recursion. As we have already defined parent, male, mother, father, haschild, brother, sister, grandparent, wife, and uncle family relationship and now we will see predecessor relationship. If P is the parent of Q then obviously P can be treated as a predecessor of Q, but if we go one step that means if P is the parent of Q and Q is the parent of R then we can say that P is the predecessor of R, similarly, if P is the parent of Q1 and Q1 is the parent of Q2 and Q2 is the parent of R then P can be called as the predecessor of R. In this way, we can move up to n number of levels.

predecessor(P,R):- parent(P,R). predecessor(P,R):- parent(P,Q),predecessor(Q,R).

In the above clauses we have declared predecessor(P, R) clause, we can demonstrate or say the above clause as the predecessor(P, R) if a parent(P, R) otherwise predecessor(P, R) if the parent(P, Q) and predecessor(Q, R), so in this way in predecessor declaration we use recursion. In the case of recursion, it has two issues one is that recursion has some base case where the algorithm gets terminate, the recursion algorithm must have a calling instruction itself either directly or indirectly. The predecessor(P, R) will be nothing but if P is one level higher than R then it will work otherwise we will go for multilevel higher. We are using predecessor on left and right both so that why it is a good example of recursion.

Example #1

Code:

:-initialization(main). main :- write('Recursion'). sumlist([], 0). sumlist(Item, SumOfItem), Sum is First + SumOfItem.

Input:

sumlist([4, 2, 3], Answer).

Output:

In the above program, we use recursive procedure ‘sumlist’, in every recursive call of ‘sumlist’ there is a separate instance of variables First, Item, Sum, SumofItem, and these are distinguished by a subscript, so it created First1 instance for First to call ‘sumlist’ and also First2 instance created for First in first recursive calling to call ‘sumlist’. We wrote a program to show the sum by putting the input which is given above.

Example #2

Code:

:- initialization(main). main :- write('fact and rule in recursion'). hat(beautiful). item(X) :- hat(X).

Input:

hat(beautiful).

hat(X).

Output:

In the above example, we explain the working of facts and rules in recursion by using prolog computer language. As prolog has an in-built predicate true/0 is always true. Hence to ask for given facts, we have given input as ‘hat(beautiful).’ it will give an output Yes. And when we give input ‘hat(X).’ then it will give the output with its value provided in code so it is ‘X=beautiful’ with yes, which is shown in the screenshot.

Conclusion

In the above article, we conclude that the prolog recursion is a technique to refer itself with some goal, it has declarative syntax with its rules, which has predecessor logic to show the relationship between family, we can also conclude that prolog is very comfortable with using recursive rules by using recursion we can easily find the ancestor.

Recommended Articles

We hope that this EDUCBA information on “Prolog Recursion” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

How Json Works In Postgresql?

Definition of PostgreSQL JSON

JSON is an abbreviation of JavaScript Object Notation. JSON stores value in key-value pair; it is an open standard format. We generally prefer JSON for sending/receiving or exchanging data between servers and in web applications. The data within JSON is in text format, which is easily human-readable. PostgreSQL version 9.2 introduced support for the native JSON data type. PostgreSQL provides various methods and operators to work with JSON data.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

column_name json  How JSON Works in PostgreSQL?

We need to make sure the given data is in a valid JSON format before adding it to the table.

If JSON data is incorrect, then it will throw an error.

PostgreSQL provides the two native operators to work with JSON data.

How to Insert JSON Data?

To understand the insertion of JSON data, let us create a ‘student’ table with the following structure.

The student table consists of two columns:

stud_id: The column is the primary key column that uniquely identifies the student.

stud_data: The column which stores the student’s information in the form of JSON.

Let’s create the table by using the CREATE TABLE statement:

CREATE TABLE student ( stud_id serial NOT NULL PRIMARY KEY, stud_data json NOT NULL );

Now we will insert the data into the stud_data column, which is of type JSON. Before adding JSON data to the table, we need to ensure the given data is invalid in JSON format. Now insert the JSON data with the help of the following INSERT statement, which will add a new row into the ‘student’ table.

INSERT INTO student (stud_data) VALUES ( '{ "name": "Oliver Jake", "information": { "mobile_number": "9999999999", "branch": "Computer", "rank":12 } }' );

After executing the above statement, illustrate the student table’s content using the following snapshot and SQL statement.

select * from student;

Output:

We can insert multiple rows in the table using the following INSERT statement:

INSERT INTO student (stud_data) VALUES ( '{ "name": "Jack Connor", "information": { "mobile_number": "9999999910", "branch": "Computer", "rank":1 } }' ), ( '{ "name": "Harry Callum", "information": { "mobile_number": "9999999911", "branch": "Civil", "rank":2 } }' ), ( '{ "name": "Jacob John", "information": { "mobile_number": "9999999912", "branch": "Electrical", "rank":6 } }' ); select * from student;

We can fetch the data from the student table by using the following snapshot and SQL statements.

Output:

Examples of PostgreSQL JSON

We have created a student table in the above section; let’s use the same for understanding the following examples.

Example #1 – Get all students in the form of JSON key SELECT FROM student;

Output:

Example #2 – Get all students in the form of JSON text SELECT FROM student;

Output:

Example #3 – Get specific JSON node using operators SELECT FROM student ORDER BY rank;

Output:

Example #4 – Use JSON operator in WHERE clause

In order to filter rows from the result set, we can use the JSON operators in the WHERE clause. Consider the following example, which gives us the record whose branch is Computer by using the following statement.

SELECT FROM student WHERE

Output:

Example #5 – PostgreSQL JSON functions

PostgreSQL provides us with some functions to handle JSON data.

json_each function

By using the json_each() function, we can expand the outermost JSON object into a set of key-value pairs as follows:

SELECT json_each (stud_data) FROM student;

We can use the json_each_text() function to get a set of key-value pairs as text.

json_object_keys function

We can use the json_object_keys() function to get a set of keys in the outermost JSON object as follows:

SELECT FROM student;

json_typeof function

With the help of the function json_typeof(), we can get the type of the outermost JSON value as a string. The type of JSON value can be a boolean, number null, string, object, and array.

We can get the data type of the information using the following statement:

SELECT FROM student;

Output:

We can get the data type rank field of the nested information JSON object using the following statement:

SELECT FROM student;

Output:

Advantages of using JSON in PostgreSQL

Advantages of using JSON in PostgreSQL are given below:

Avoid complicated joins.

Parsing of JSON data is quite easier and faster execution.

Compatible with various database management systems.

Javascript Notation Objects are faster and very easy to read and understand.

The data within the JSON object is separated by a comma, making it easily understandable.

JSON is lightweight for data exchange.

Conclusion

From the above article, we hope you understand how to use the PostgreSQL JSON data type and how the PostgreSQL JSON data type works to store the data in key-value pair. Also, we have added some examples of PostgreSQL JSON to understand it in detail.

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL JSON” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

How Switch Works In Kotlin?

Introduction to Kotlin switch

Web development, programming languages, Software testing & others

Syntax

In kotlin language have many default classes, methods, and other default variables used to implement the application in both UI and backend logic. The switch is one of the features and it is a loop case statement to iterate the values but now kotlin uses when keywords instead of switch.

{ val vars; when(vars) { —some logic and conditional statement codes—- } }

The above codes are the basic syntax for using the when keyword instead of switch blocks in the kotlin language. The looping and other conditional statements are evaluated and validated by the programmer.

How does Switch work in Kotlin?

The switch is one of the statements that can be used to declare and construct the loops to iterate the user input values. In kotlin language when a keyword can be used to declare the expression or statement while using that it can also satisfied with the branch’s value becoming the value of all the expressions. Each case statement is used with the individual branches the values are ignored and it is used with the default cases like java switch statement the else is the mandatory one when it used as the expression. If we used when keywords without any expressions it will act as the if-else chain blocks the boolean conditions and expressions also validated with specified logics. It is helpful when the user has n number of choices that want to be performed with the different tasks for each other choices. Mainly the switch statement allows for testing the variable in an equality manner against the list of values. Each value is defined and it is known as the cases generally the switch statement used break keyword for breaking the lines but is not a required manner it seems to be optional. Instead of switch when keyword used same case statements but here break keyword is not used and also we can use else statement if it is required.

Examples of Kotlin switch

Given below are the examples of Kotlin switch:

Example #1

Code:

package one; import java.util.* fun main() { var str1: String? = null var str2: String? = "Welcome To My Domain is the first example that relates to the Kotlin Switch statement" var strlen1: Int = if (str1 != null) str1.length else -1 var strlen2: Int = if (str2 != null) str2.length else -1 println("Length of str1 is ${strlen1}") println("Length of str2 is ${strlen2}") println("Enter the Color code from these jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec") val vars = readLine() val vars2 = when (vars) { } println("$vars2") println("Thank you users for spenting the time with our application") val sc = Scanner(System.`in`) print("Enter the numbers: ") val inp1 = sc.nextDouble() val inp2 = sc.nextDouble() val inp3 = sc.nextDouble() val inp4 = sc.nextDouble() val inp5 = sc.nextDouble() print("Please choose the operator to perform the mathematical operations (+, -, *, /): ") val opn = sc.next()[0] val out: Double when (opn) { System. out.printf("The operations are failed because due to the wrong inputs") return } } System.out.printf("%.1f %c %.1f = %.1f", inp1, opn, inp2, out) }

Sample Output:

In the above example, we calculate the mathematical operations by using the when statement.

Example #2

Code:

package one; import java.util.Scanner; fun demo(new: Any) = when (new) { } var str = Scanner(System.`in`) print("Please enter your brand:") var bndName = str.nextInt() var out = when(bndName){ println("Your brand is not listed here") } } println(out) var new = "Welcome To My Domain its the first example that relates to the Kotlin switch concept" var res = demo(new) if(res) { println("Yes, Your brand is listed Welcome To My Domain its the first example that relates to the Kotlin switch") } else { println("No, Sorry your brand is not listed here Kindly try with one more and please stay with our application and spent your valuable time for us thanks") } }

Sample Output:

In the second example we used to check the brand conditions with corresponding values with the help of the when statement.

Example #3 package one; import java.util.Scanner; enum class Textile { CHENNAISILKS, POTHYS, SRAVANASTORES, MJS, SPJ, SIVATEXTILE } fun main() { val result = Textile.POTHYS when (result) { } }

Sample Output:

In the final example, we used enum and we can create the reference of the enum and we called and iterate the enum values using the when statement.

Conclusion

In the kotlin language, we used many different concepts and features to implement the mobile with web-based applications. Like that the Switch is one of the looping and conditional expressions to validate the input data from both front and backend. We can use “when” keyword to achieve these switch case logics in the kotlin application.

Recommended Articles

This is a guide to the Kotlin switch. Here we discuss the introduction, syntax, and working of switch in Kotlin along with different examples and code implementation. You may also have a look at the following articles to learn more –

Update the detailed information about How List Function Works In Php on the Moimoishop.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!