Mike Corrato
Mike Corrato

Reputation: 85

Remove string length value from PHP array result

I have a PHP associative array that I am trying to extract data from:

array(18) { ["body"]=> string(34) "Hey! Let me know if you got this"}

The above array is stored in a variable called $firstChildData, and when I try to run the following line, I get the result below it:

$firstChildBody = $firstChildData["body"];

This returns: string(34) "Hey! Let me know if you got this"

Does anyone know how to remove the 'string(34)' so I can just have the value within the quotes? I have tried to use the explode() function with " as the delimiter, but that didn't work.

Thanks in advance!

Upvotes: 3

Views: 1031

Answers (2)

Mike Corrato
Mike Corrato

Reputation: 85

Thanks everyone!

You're right, I was using var_dump, which was showing that information even thought it was not part of the string. I used echo instead and it works beautifully.

Upvotes: 1

Richard
Richard

Reputation: 2815

string(34) is just a debug information if you use a function like var_dump or print_r.

You can print strings normal with echo or print.

echo $firstChildData["body"];

If you want to use the variable $firstChildData["body"] in any program code, it is handled as the string in it. The information string(34) ist not included.

Upvotes: 3

Related Questions