In this Article Iam explain 5 popular array functions
1). is_array() function
syntax: is_array($argument)
$argument = array('value1','value2'); if(is_array($argument)){ echo 'array'; } else { echo 'Not an array'; } // Output:- array2). in_array() function
syntax: in_array($search_value,$array,type);
type is optional part in in_array function,If the search parameter is a string and the "type" parameter is set to TRUE, the search is case-sensitive.
$friends = array('srinu','karthik','suneel','Bhaskar'); if(in_array("Bhaskar",$friends)){ echo 'value found in an array'; }else{ echo 'value not found'; } //Output:- value found in an array3). array_merge() function
syntax:array_merge($array1,$array2);
$first_array = array('car','bus'); $second_array = array('train','flight'); $array_merge_result = array_merge($first_array,$second_array); print_r($array_merge_result); Output:- Array ( [0] => car [1] => bus [2] => train [3] => flight )4).list() function
$testarray = array("Dog","Cat","Horse"); list($a, $b, $c) = $testarray; echo $a; //Dog echo $b; //Cat echo $c; //Horse5).count() function
$testarray = array('one','two','three'); echo count($testarray); //output:- 3
No comments:
Post a Comment