比如話黎個array有兩件product,入面item_meta_array有佢地既product id
我想印兩個id出黎即係213同65
https://gist.github.com/ben1one/367eac79bd11be0c05b0f05c213a402a
有無好直接既方法可以囉到?因為佢個number key唔係固定的
黎個係我既寫法,但有無更直接既寫法?- foreach ( $order_item as $item ) {
- $pid = findObj($item['item_meta_array'], "_product_id");
- echo $pid."<br/>";
- }
- function findObj($input, $key){
- foreach ($input as $k => $v ) {
- foreach ( $v as $k2 => $v2 ) {
- if($k2=="key" && $v2 ==$key){
- return ($v->value);
- }
- }
- }
- return "";
- }
複製代碼 |