<?php
$myArray1 = array("MyKey1" => "MyValue1", "MyKey2" => "Value2", );
echo "The value assigned to Key1 is , " $myArray["MyKey1"];
$myArray2 = array("MyKey3" => "MyValue3", "MyKey4" => "MyValue4", );
//Merge them into one array
$myArray1 = ($myArray1, $myArray2);
//Iterate through the keys and values of the array
foreach ($myArray as $key => $value)
{
echo $key, "", $value, "<br>";
}
//Check to see if a key exists
if(array_key_exists($myArray1["MyKey1"])) echo $myArray1["MyKey1"];
//Search for a value
$valueSearch = array_search("MyValue2", $myArray1)
echo "The key for MyValue1 is ", $valueSearch;
//Print the keys of the array in a human readable format
print_r(array_keys($myArray1));
//Print the values of the array in a human readable format
print_r(array_values($myArray1));
?>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
I'm not going to get into multidimensional arrays.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'''''''''''''''''''''''''''''''''''''''''''''
!!Explode these Countries!!
<?php
$countryStr = "Cuba,France,New Kidney,Paraguay";
$randCountry = explode(",", $countryStr);
echo $randCountry[1];
?>
!!Implode!!
<?php
$
countryStr
= explode(", ", $
randCountry
);
?>
!!Reverse!!
print_r(array_reverse($ranCountry,true))
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
I'm not going to get Sorting or Counting.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
You can also create arrays from an external txt file. I am not going to get into file manipulation.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
No comments:
Post a Comment