php - Searching for values in JSON array w/ stdClass subarray -


this json snippet part of woocommerce order, extracted apiv2 get_order() function. [meta] holds product variation data chosen customer.

[meta] => array ( [0] => stdclass object ( [key] => pa_size [label] => size [value] => large ) [1] => stdclass object ( [key] => pa_color [label] => choose color [value] => black )

how search stdclass object particular [key] , return corresponding [value]?

<?php    $meta = array();   //suppose array $meta     $your_key="pa_size"; // if trying search "pa_size"    $your_value=""; // retrun value "large"     foreach( $meta $obj )    {         if( $obj->key == $your_key )         {             $your_value = $obj->value;             break;         }    }     echo $your_value; // retrun value "large" ?> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -