i have little complex array with languag english and french, i just want switch with button
$_GET['lang-fr'] and $_GET['lang-en']
that my array and code with foreach...
i have array multidmension, with first key, lang-fr =>
and i use 3 foreach but i don't know if i have best practice
$experiences = [
'lang-fr' => [
[
'name' => 'poissonerie',
'address' => 'impasse de la tête coupee',
'date' => '1350',
'description' => 'bonne experience, patron delicieux avec ses employes',
],
],
'lang-en' => [
[
'name' => 'blablz',
'address' => 'cut head',
'date' => '1350',
'description' => 'boss so delicious',
],
],
];
foreach ($experiences as $lang => $experience) {
if (isset($_GET['lang-fr'])) {
foreach ($experience as $arrayIn => $other) {
echo ' <div class="time">';
echo ' <span class="rounded"></span>';
echo ' <span class="line"></span>';
echo '</div>';
echo '<div class="data-experiences">';
foreach ($other as $key => $value) {
switch ($key) {
case 'address' === $key:
echo '<i>'.$lang[$value].'</i>'.'</br>';
break;
case 'date' === $key:
echo '<time>'.$lang[$value].'</time>'.'</br>';
break;
case 'description' === $key:
echo '<mark>'.$lang[$value].'</mark>'.'</br>';
break;
default:'name' === $key;
echo '<h4>'.$lang[$value].'<h4>';
break;
}
}
echo '</br></div>';
}
}
My Answer:
In PHP, you can fetch multi-dimensional arrays using the $_GET superglobal variable. Here is an example of how you can fetch a multi-dimensional array using $_GET:
php
// Assuming the URL is something like: example.com/?data[0][name]=John&data[0][age]=30&data[1][name]=Jane&data[1][age]=25
$data = $_GET['data'];
foreach ($data as $key => $value) {
echo "Person " . $key . ":
";
echo "Name: " . $value['name'] . "
";
echo "Age: " . $value['age'] . "
";
echo "
";
}
In this example, we are fetching a multi-dimensional array from the URL parameters using $_GET['data']. We then loop through each element of the array and display the name and age of each person.
Rate this post
4 of 5 based on 1831 votesComments