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
Post a Comment