Array Function in Php

What is array?
An array is a container object that hold a fixed number of values of a single type. The length of an array is established when the array is created.

There are some important array Function mentione below.
1 list() ; This function is used to assign variable as if they were an array.

Remark: This function only work on numerical array.

list($a,$b)=array("Hari","Sharma");
echo $a;//output Hari
echo $b;//output Sharma

2. is_array(): find the variable weather is in array or not.

e.g

$yes = array('this', 'is', 'an array');
echo is_array($yes) ? 'Array' : 'not an Array';echo "\n";$no = 'this is a string';
echo is_array($no) ? 'Array' : 'not an Array';



output:

Array
not an Array



3. in_array : Checks if a value exists in an array.
e.g

$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true))
 {    
echo "'12.4' found with strict check\n";
}
if (in_array(1.13, $a, true)) {   
 echo "1.13 found with strict check\n";
}
 output: 1.13 found with strict check
 

Comments