0

Asking a simple question,

$a = [array(]2, 4, 6, 8);

     echo $a;

why return Array in html page and not the numbers?

1
  • because of its array see this link Commented Oct 30, 2016 at 10:34

2 Answers 2

1

Firstly, that's not the way to declare an array in php. You declare it like this:

$a = array(2, 4, 6, 8);

or like this:

$a = [ 2, 4, 6, 8 ];

Secondly, "echo" prints strings. An array is not a string. If you want to print the contents of an array you can use:

print_r($a);

or:

var_dump($a)

or:

foreach($a as $number)
{
   echo($number.' ');
}

or:

echo(implode(',', $a));

or:

echo($a[0]);
echo($a[1]);
// etc
Sign up to request clarification or add additional context in comments.

Comments

0

You can use this to display print_r($a)

Comments

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.