Home > Software design >  How to get the value of specific array in php
How to get the value of specific array in php

Time:10-09

I have this code in woocommerce using php. I do print_r($meta[1]) and it has output below

WC_Meta_Data Object ( [current_data:protected] => Array ( [id] => 455885 [key] => _end_date_custom_field [value] => 2023-01-18 ) [data:protected] => Array ( [id] => 455885 [key] => _end_date_custom_field [value] => 2023-01-18 ) )

How can get the value of [value] key? I tried different combinations but not working

i tried echo($meta[1][value]); but it is not working what did i do wrong?

CodePudding user response:

Looking at the WooCommerce docs, the WC_Meta_Data class has implemented the __get magic method and has the comment Returns the value of any property., so I would assume you could do :

$meta[1]->value

Cheers

  • Related