0
Good afternoon, I’m walking little by little in php, but this part of array I still get very confused, I researched a lot on the internet and I read in the php manual but I can’t do what I want, I’m doing some tests with wordpress, in it I am using an api that returns me an array with multiple results, wanted to store a specific part of that array, follows the array when I give print_t
Array (
[0] => stdClass Object (
[id] => 10978
[code] => al060819#3
[amount] => 90.00
[date_created] => 2019-08-05T13:35:28
[date_created_gmt] => 2019-08-05T18:35:28
[date_modified] => 2019-08-05T18:52:58
[date_modified_gmt] => 2019-08-05T23:52:58
[discount_type] => percent
[description] =>
[date_expires] => 2019-08-07T00:00:00
[date_expires_gmt] => 2019-08-07T05:00:00
[usage_count] => 15
[individual_use] =>
[product_ids] => Array ( )
[excluded_product_ids] => Array ( )
[usage_limit] =>
[usage_limit_per_user] =>
[limit_usage_to_x_items] =>
[free_shipping] =>
[product_categories] => Array ( )
[excluded_product_categories] => Array ( )
[exclude_sale_items] =>
[minimum_amount] => 0.00
[maximum_amount] => 0.00
[email_restrictions] => Array ( )
[used_by] => Array (
[0] => 88
[1] => 90
[2] => 92
[3] => 89
[4] => 99
[5] => 101
[6] => 100
[7] => 102
[8] => 106
[9] => 108
[10] => 116
[11] => 117
[12] => 116
[13] => 123
[14] => 122 )
[meta_data] => Array (
[0] => stdClass Object (
[id] => 25606
[key] => count_items
[value] => 0 )
[1] => stdClass Object (
[id] => 25619
[key] => slide_template
[value] => default ) )
[_links] => stdClass Object (
[self] => Array (
[0] => stdClass Object (
[href] => Null) )
[collection] => Array (
[0] => stdClass Object (
[href] => Null ) ) ) ) )
wanted to access used_by and save in another variable, tried in some ways, but all returned error ex:
$teste = $array[0]['used_by'];
or
$teste = $array['used_by'];
msg of error :
Fatal error: Uncaught Error: Cannot use object of type stdClass as array in C:\xampp\htdocs\teste.php:37 Stack trace: #0 {main} thrown in C:\xampp\htdocs\teste.php on line 37
Could someone please explain to me how it works? because I’m very lost in it, sorry for the stupid question, I think it can be repeated, but I researched a lot earlier and I couldn’t understand, I thank you from the beginning.
If the data is JSON, the link above will answer the question.
– Woss