Php retrieves array value array inverted key name Operation instance

Source: Internet
Author: User
Tags php tutorial

*/

$ Array = array ("size" => "xl", "color" => "gold"); // defines an array
Print_r (array_values ($ array); // outputs all values of the array.

/*
Definition and usage
The array_values () function returns an array containing all the key values in the given array without retaining the key name.

Syntax
Array_values (array)
*/

$ Fruit = array ('a' => 'apple', 'B' => 'bana', 'C' => 'Cranberry '); // define an array
Reset ($ fruit); // move the pointer to the first position
While (list ($ key, $ val) = each ($ fruit) // cyclically outputs the key/value pair of the array and moves the pointer
{
Echo "$ key => $ valn"; // outputs the key and value of the array.
}

/*

*/

$ Input = array ("php Tutorial", 3.0, array ("green", "red"); // defines an array
$ Result = array_reverse ($ input); // reverse the array without retaining the key name
$ Result_keyed = array_reverse ($ input, true); // reverse the array and retain the key name
Print_r ($ result); // display the first result
Print_r ($ result_keyed); // The second result is displayed.

/*
Definition and usage
The array_reverse () function switches the elements in the original array sequentially, creates a new array, and returns the result. If the second parameter is set to true, the key name of the element remains unchanged; otherwise, the key name is lost.

Syntax
Array_reverse (array, preserve)
*/

$ Array = array (0 => 100, "color" => "red"); // defines an array
Print_r (array_keys ($ array); // return all key names of the array
$ Array = array ("blue", "red", "green", "blue", "blue"); // defines an array
Print_r (array_keys ($ array, "blue"); // The key name whose return value is blue
// Define an array of elements as an array
$ Array = array ("color" => array ("blue", "red", "green"), "size" => array ("small", "medium ", "large "));
Print_r (array_keys ($ array); // return all key names of the array

/*
Definition and usage
The array_keys () function returns a new array containing all the key names in the array.

If the second parameter is provided, only the key name of the value is returned.

If the strict parameter is set to true, php will use full comparison (=) to strictly check the data type of the key value.

Syntax
Array_keys (array, value)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.