-1

I am getting an error saying

Parse error: syntax error, unexpected '[' in /home/ajayi/public_html/html/arrays.php on line 14

When I added the sort is when I started getting the error. What I am trying to do is have the names of the fruits sorted in alphabetical order.

this is my code...

$myArray = array('0' => 'tangerine' , '1' => 'orange' , '2' => 'kiwi', '3' => 'strawberry' , '4' => 'banana', '5' => 'grape', '6' => 'pear' , '7'=> 'apple');

echo "<table border ='2px black solid'>";
for ($x = 0; $x < 8; $x++){
echo "<tr>";
for($y = 0; $y < 10; $y++){
echo "<td>".sort($myArray)[$x][$y]."</td>";
}
echo "</tr>";
}
echo"</table>";
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
hannah
  • 11
  • 3

1 Answers1

0

I have changed the position of the sort line so that the sort line is only called one time. (See comment of "Mark Baker"). The echo of the array value is still present on the original location.

$myArray = array('0' => 'tangerine' , '1' => 'orange' , '2' => 'kiwi', '3' => 'strawberry' , '4' => 'banana', '5' => 'grape', '6' => 'pear' , '7'=> 'apple');

sort($myArray);
echo "<table border ='2px black solid'>";
for ($x = 0; $x < 8; $x++){
    echo "<tr>";
    for($y = 0; $y < 10; $y++){
         echo "<td>" . $myArray[$x][$y] . "</td>";
    }
    echo "</tr>";
}
echo"</table>";