0

I have some data in an associative array and when I pass each element of the array to a variable, it only gets the first character of the string.

For example:

array (size=5)
  'data' => 
    array (size=14)
      'number' => string '321335' (length=6)
      'text' => string 'abcde' (length=5)
$number = $commentData['data']['number'];
$text = $commentData['data']['text'];

echo $text;
// Output: a
echo $number;
// Output: 3

I expected to return all string on variable. I tried:

echo $commentData['data']['number'];
// Output: a
echo $commentData['data']['text'];
// Output: 3
2
  • Can you show the result of var_dump($commentData);? Commented Jun 7, 2023 at 14:30
  • Better still, show us var_export($commentData); instead, then the output will be re-usable as PHP code, so we can test it easily and make examples / answers without having to re-key it. Thanks. php.net/manual/en/function.var-export.php . Based on what you've shown so far, we don't appear to have a minimal reproducible example of the issue. What you are stating, does not seem to be possible, based on the (admittedly limited) data provided. Commented Jun 7, 2023 at 15:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.