Exn
Exn

Reputation: 809

how to get correct data from this array?

This answer might seem simple but I am new to PHP and spending way too much time on trying to figure this out.

My array looks like this:

        $phone_number[] = array(
            "type" => "home",
            "value" => $customer_phone                    
        );

and I have also this:

 $customer = array(
                "first_name" => $first_name,
                "phone_numbers" => $phone_numbers,
                "emails" => $emails,

I want to retrieve the number for each customer. I have tried this:

     for ($j = 0; $j <= count($customer_entries) - 1; $j++) {


      var_dump($customer_entries[$j]->phone_numbers->value);
     }

But it gives me an error. It says I am trying to get property of non object, and then it says null.

But when I use:

 var_dump($customer_entries[$j]->phone_numbers;

it gives me something like this:

array(1) {
[0]=>
object(stdClass)#744 (2) {
["type"]=>
string(4) "home"
["value"]=>
string(14) "(555) 555-5555"
 }
}

How do I get it to only give me the result of the string named "value"?

Thank you.

Upvotes: 0

Views: 49

Answers (1)

Beardminator
Beardminator

Reputation: 774

$customer_entries[$j]['phone_numbers']['value']

Use it as an array,not an object.

Upvotes: 1

Related Questions