I am having a bit of trouble with this PHP code. I am not sure why it is printing Array 8 times. From what I see, it should be printing the contents of the array
The goal is to declare an array, using a global, define the array, assign it to another array and display the entire array.
$car_array = array( );
$array = array( );
create_array_cars ();
displayProduct ($array);
function create_array_cars ( ) {
global $car_array;
$car_array = array( );
$car_array[] = "ID: 12345" ;
$car_array[] = "ID: 45678" ;
$car_array[] = "ID: 67890" ;
$car_array[] = "ID: 89123" ;
return $car_array;
}
function displayProduct ($array) {
global $array;
for ($i=0;$i<4;$i++) {
print "$array<br>"; }
}
$array = create_array_cars();
print (displayProduct($array));