I
I
iurakuleshov2020-05-13 19:32:11
PHP
iurakuleshov, 2020-05-13 19:32:11

How to get value from multidimensional array?

Hello, tell me how to implement such an idea, there is a multidimensional array (the number of arrays can change)

array(3) 
{     [0]=> array(10){ 
         ["id"]=> string(2) "12"
         ["title"]=> string(10) "Шорты" 
         ["description"]=> string(22) "вывфвфывфвф" 
         ["image"]=> string(0) "" 
         ["dimensions"]=> string(0) "" 
         ["data"]=> string(10) "2020-05-10"
         ["category_id"]=> string(1) "1"
         ["user_id"]=> string(2) "24" 
         ["amount"]=> string(1) "3"
         ["price"]=> string(2) "59" }
    [1]=> array(10) { 
         ["id"]=> string(2) "13" 
         ["title"]=> string(4) "2222" 
         ["description"]=> string(8) "23123123" 
         ["image"]=> string(14) "zpvmful5ll.jpg" 
         ["dimensions"]=> string(7) "268x249" 
         ["data"]=> string(10) "2020-05-10" 
         ["category_id"]=> string(1) "1" 
         ["user_id"]=> string(2) "24"
         ["amount"]=> string(1) "3" 
         ["price"]=> string(2) "60" } 
    [2]=> array(10) { 
         ["id"]=> string(2) "16" 
         ["title"]=> string(10) "Кофта" 
         ["description"]=> string(4) "1121" 
         ["image"]=> string(14) "xqgdre8ib8.jpg"
         ["dimensions"]=> string(7) "268x249"
         ["data"]=> string(10) "2020-05-11" 
         ["category_id"]=> string(1) "6" 
         ["user_id"]=> string(2) "24"
         ["amount"]=> string(1) "1" 
         ["price"]=> string(2) "19" } }

I need to extract the record "price" with its value from each array, please tell me how it is possible to implement

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2020-05-13
@iurakuleshov

print_r(array_column($array, 'price'));
https://www.php.net/manual/en/function.array-column.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question