Please Help, I have written the PHP code shown below. I want to "echo" the array so it displays "Screwdriver Hammer Nail Screw" randomly on my page. But instead it just echo's "Array" Does anyone know where I am going wrong??? the url for the file is www.buildyourowncomputer.info/test.php
<?php $products = array ( "Screwdriver", "Hammer", "Nail", "Screw", );
shuffle($products);
echo $products; ?>
Many Thanks
foreach ($array as $value){ print "$value"; };
I have now changed my code but it is still doing the same thing. I changed the code to this. Is this right??
<?php
$products = array ( "Screwdriver", "Hammer", "Nail", "Screw", );
shuffle($products); { print "$products"; }; ?>
Try reading stevesweetland's post.
I don't understand the reply 😕 Do you know what I have done wrong in the code??
Originally posted by lcp03o I don't understand the reply 😕
Did you read stevesweetland's post? What did it say? Seems pretty easy to understand to me.
Yes, I do know what's wrong with your code. I also know that the solution has already been given. I also know that for all the attention you've been paying, stevesweetland might as well have been talking to a brick wall.
I do understand what he is saying, but I am only a beginner at PHP, and have no idea which code to add/edit. This is why I have posted here. I understand that you dont use the command print array, you have to print an item/value within the array, but I don't know how to do this. Please only post of you wish to help.
<?php //declare the array of products $products = array("Screwdriver", "Hammer", "Nail", "Screw"); //re-arrange order of products by pseudo-random algorithm shuffle($products); //loop through the array foreach ($products as $product) { //print the current array element followed by a space echo $product . ' '; } ?>
Thanks for the reply, I have changed my .php file and uploaded it to www.buildyourowncomputer.info/test.php but when I browse to it, it just displays "Array Array Array Array" and not anything in the array. Any ideas??
Thanks
Got it working now. Thanks for your help!!!