PHP array basics
- 2020-03-31 21:07:02
- OfStack
There are many PHP functions, and you can query the API when you need to.
<?php
//Creates an array of even Numbers from 0 to 20 with 2 as the step size
$even=range(0,20,2);
//Print the array
print_r($even);
//Determines whether it is an array
printf("this number is an array:%s<br/>",(is_array($even)?"true":"false"));
echo "<br>";
//The array header adds a subitem and prints it
array_unshift($even,522,54);
print_r($even);
//Define a variable, and then search the array, showing that the variable was found when it existed.
$sa=522;
if(in_array($sa,$even)){
echo "find it $sa";
};
echo "<br/>";
//Search the array key
if(array_key_exists(4,$even)){
echo $even[4]." exists.";
}
echo "<br/>";
print_r(array_values($even));
// traverse Print the array
while($key=key($even)){
echo "<br/>".$key;
next($even);
}
//Statistical array size
echo "<br/>";
echo count($even);
//The sorting
echo "<br>";
sort($even);
print_r($even);
?>