-1

I call a function to get an array and use var_dump()

the result is the following array:

array(1) {
    [0]=> array(12) {
        ["access_id"] => string(1) "1"
        ["invoice_id"] => NULL
        ["invoice_public_id"] => NULL
        ["invoice_payment_id"] => NULL
        ["invoice_item_id"] => NULL
        ["user_id"] => string(1) "1"
        ["product_id"] => string(1) "2"
        ["transaction_id"] => NULL
        ["begin_date"] => string(10) "2015-12-24"
        ["expire_date"] => string(10) "2016-01-24"
        ["qty"] => string(1) "1"
        ["comment"] => string(0) ""
    } 
}

I only need this part :

["product_id"]=> string(1) "2"

How can i get that part only from the array?

6
  • If you only want product_id you can just use a simple echo to print the key and value in that specific format. var_dump() is a debugging function to show the entire array. Commented Jan 7, 2016 at 22:43
  • Please: 1. format your code; 2. read the docs on php arrays Commented Jan 7, 2016 at 22:44
  • echo $array[1]['product_id']; I guess Commented Jan 7, 2016 at 22:45
  • echo $array[0]['product_id']; Yes mate this is correct. I was doing it like this : echo $array['product_id'][0]; and it wasn't working. Thanks a lottt. Commented Jan 7, 2016 at 22:50
  • @jamesll So you just want to access the product_id, it's not about that specific format? Commented Jan 7, 2016 at 22:52

2 Answers 2

0

You can simply access the value directly:

echo $myArray[0]['product_id'];

You may want to start reading the documentation about arrays in php: http://php.net/manual/en/language.types.array.php

Sign up to request clarification or add additional context in comments.

1 Comment

Yes thanks a lottttt. This solved my problem.
-1

var_dump($yourArray[0]['product_id']);

You should not use var_dump for production, only for debugging.

3 Comments

This will give OP an undefined index
Yes rizier123 is right.It gave me NULL.
Undefined index fixed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.