Issue
Here is my problem. I have created two bunny's with character and want to display them, als with PHP.
For the two bunny's I created a multidimensional array:
$bunnys = array(
array( //$bunny
array(' ', ' ', '(', ')', ' ', '(', ')', ' ', ' '), //$row en in de array is $piece
array(' ', ' ', '(', 'o', '.', 'o', ')', ' ', ' '),
array('\'', '(', '"', ')', ' ', '(', '"', ')', '\''),
),
array(
array(' ', ' ', '(', ')', ' ', '(', ')', ' ', ' '),
array(' ', ' ', '(', '>', '.', '<', ')', ' ', ' '),
array('\'', '(', '"', ')', ' ', '(', '"', ')', '\''),
),
);
Then I want to echo the bunny's using the foreach loop:
echo "<pre>";
foreach($bunnys as $bunny)
{foreach ($bunny as $row)
{foreach ($row as $piece)
echo "$piece";
echo "<br>";
}
}
echo "</pre>";
Actual result The problem is, is that the bunny's are standing underneath eachother, like this:
() ()
(o.o)
'(") (")'
() ()
(>.<)
'(") (")'
Desired result But what I want, is that the bunny's standing next to each other, like this:
() () () ()
(o.o) (>.<)
'(") (")''(") (")'
I already tried to delete the echo "<br>";
, but then the result is that there are six lines.
Anybody havind an idea what I am doing wrong?
Solution
$bunnys = array(
array( //$bunny
array(' ', ' ', '(', ')', ' ', '(', ')', ' ', ' '), //$row en in de array is $piece
array(' ', ' ', '(', 'o', '.', 'o', ')', ' ', ' '),
array('\'', '(', '"', ')', ' ', '(', '"', ')', '\''),
),
array(
array(' ', ' ', '(', ')', ' ', '(', ')', ' ', ' '),
array(' ', ' ', '(', '>', '.', '<', ')', ' ', ' '),
array('\'', '(', '"', ')', ' ', '(', '"', ')', '\''),
),
);
$bunnysArray1 = $bunnys[0];
$bunnysArray2 = $bunnys[1];
foreach ($bunnysArray1 as $k=> $v){
echo implode('',$v);
echo implode('',$bunnysArray2[$k]);
echo php_sapi_name() == "cli" ? PHP_EOL : '<br>';
}
output
() () () ()
(o.o) (>.<)
'(") (")''(") (")'
see in action https://onlinegdb.com/yP0-SxazPR
Answered By - Abdurrhman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.