

#Php associative array get all values how to#
see redreggae's answer for how to get just the values. I do not need the 'user_email' key/value pair.Not sure it'll suit you, as it's PHP >= 5. Assuming keys in the sub arrays are unique you can. i am trying to get all array values of an multidimentional array, but the thing is array can be 1 levels deep or 2, 3 or 4, i.e. It won't work anywhere because you're passing a string, not an actual array. These are the fields I'd like to get from the $post_data array Assuming keys in the sub arrays are unique you can. The syntax for accessing elements in an associative array is arr'key'.The syntax for accessing properties of objects. PHP: How to get both key and value from an associative array 1. You can use the PHP arrayvalues () function to get all the values of an associative array. You can use the PHP arrayvalues() function to get all the values of an associative array. how to get key-value in associative array 0. Answer: Use the PHP arrayvalues() function. I'd then like to create a new array named $clean_data with these key/value pairs.īelow is my failed attempt at looping through the $post_data array and pulling out the matches based on the $my_fields array. cell is an associative array, not an object. PHP associative array get values in an array.

How can i get (echo) all names and corresponding ages in a single instance (like foreach value as value ) The array may have more data than shown here. I have an array ages array ('Peter'>32, 'Quagmire'>30, 'Joe'>34). Only where the key matches a provided list $my_fields.Īnd create a new array with only the matched data.įor example, from $post_data I'd like to grab the key/value pairs for first_name, last_name, and title while ignoring user_email. get all values from php associative array. Grab key/value pairs from an array $post_data.
