PHP - If array contains

Solution:
Create one image for each language on a folder containing the language code, like so
images/en-flag.png
images/nl-flag.png
And loop thru the array to display the images
foreach ($languagevalue as $lang) {
echo '<img src="images/' . $lang . '-flag.png" alt=""/>';
}
Answer
Solution:
Try something like this , to check existence of each item
<?php
if (in_array('nl', $languagevalue)) {
//NL image
}
if (in_array('en', $languagevalue)) {
//en image
}
if (in_array('de', $languagevalue)) {
//de image
}
if (in_array('it', $languagevalue)) {
//it image
}
?>
Answer
Solution:
I would actually create another array with the flag images by iterating over the$languagevalue
array:
$flags = [];
foreach($languagevalue as $lang) {
$flags[] = "$lang-flag";
}
Now you can iterate over$flags
.
This assumes you can derive the flag name directly from the language name. If that's not the case, you'll have to use something like aswitch
statement to map the language name to the flag image name.
Answer
Solution:
You can implode the values with the html of the end and begining of the IMG tag.
This way you don't need to loop or check if the value is in the array.
The html is generated automatically.
$languagevalue = ['NL', 'EN', 'DE'];
echo '<img src="images/' . implode('-flag.png" alt=""/> <img src="images/' ,$languagevalue) . '-flag.png" alt=""/>';
Output:
<img src="images/NL-flag.png" alt=""/>
<img src="images/EN-flag.png" alt=""/>
<img src="images/DE-flag.png" alt=""/>
Added new lines for clarifying
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: target class [commandmakecommand] does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.