how do we print the whole elements in an array? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

how do we print the whole elements in an array?

24th Jun 2016, 6:51 PM
Thesneem
Thesneem - avatar
7 Respostas
+ 2
Then just use a foreach loop: foreach($arr as $key => $value) { echo $value . ' '; }
24th Jun 2016, 7:20 PM
James Flanders
+ 1
you can use print_r() function to print the whole array. <?php $arr = array(1, 2, 3); print_r($arr); ?>
24th Jun 2016, 6:57 PM
James Flanders
0
But it gives me "Array ( [0] => 1[1] => 2[2] => 3 )" as the output.I juz wanna print the contents only, without the indeces.
24th Jun 2016, 7:09 PM
Thesneem
Thesneem - avatar
0
yeah.!! I got it..Thank you :-)
24th Jun 2016, 7:29 PM
Thesneem
Thesneem - avatar
0
Don't use print_r() method. It will only print the storing format and not the individual values of the indexes. Use echo instead
28th Jun 2016, 5:08 AM
Bello Morenikeji
Bello Morenikeji - avatar
0
u got to echo the the variable you specify for the array
8th Jul 2016, 4:29 PM
Sadeeq Suraj
Sadeeq Suraj - avatar
0
use foreach loop <?php $arr=array("John","James","Peter"); foreach($arr as $value) { echo $value."<br>"; } ?>
28th Oct 2016, 9:42 PM
David