Monday, November 14, 2022

Useful prebuilt array Method in PHP

 Useful prebuilt array Method in PHP








array( 'Search' => 'Google', 'Social' => 'Facebook', 'News' => 'NY Times' ), 'friends' => array( 'Chris', 'Jim', 'Lynn', 'Jeff', 'Joanna' ) ); echo "
";
print_r($array);
echo "
"; echo "
"; // is_array() check the variable is an array. echo is_array(($array)); echo "
"; // in_array() Check the certain value in our array $result = in_array("Google", $array['websites']); print_r($result); echo "
"; // Lets Merge two array in one array_merge(); $merged = array_merge($array['websites'], $array['friends']); echo "
";
print_r($merged);
echo "
"; // Lets bribg out merged array key using array_keys(); $keys = array_keys($merged_array); echo "
";
print_r($keys);
echo "
"; echo "
"; // check key present in array or not array_key_exists() $exists = array_key_exists(7, $keys); print_r($exists); echo "
"; // To move out array we use array_shift() $shifted = array_shift($array); print_r($shifted); echo "
"; print_r($array); echo "
"; // I want to back my shifted array in original way array_push(); array_push($array, $shifted); echo "
";
print_r($array);

echo "
";

0 comments

Post a Comment