DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        How to don't output false in every itaration

        42 Views Asked by Uros At 24 May 2022 at 12:17 2025-12-17T21:49:00.877000
        <?php
        $jobsKeys = array('full.png','hr.png','mobile.png','java.png','python.png','net.png')
        
        ?>
        <div class="row">
                     <ul class="list-group">
                     <?php foreach ($item as $job) : ?>
                            <?php
                            foreach($jobIcons as $jobsKeys){
                                if (stripos($job['title'], $jobsKeys['title']) !== false) {
                                   echo "<li class='list-group-item'><img src=".$jobsKeys['image']." style='width: 25px;'> ". $job['title'] ." <span class='badge badge-primary badge-pill'>14</span></li>";
                                }else{
                                    echo "false";
                                }
                            }
                            ?>
                     <?php endforeach; ?>
                        </ul>
                 </div>
        

        I'am trying to compare the title of the job with the icons from the array (stripos method). And condition when is true works for me the way I want, the problem is with the else statement.

        foreach loop returns somthing like this:

        false
        false
        false
        false
        false
        <li>....</li>
        false
        false
        false
        <li>....</li>
        

        I want to get somthinglike this: if you don't find match in jobIcons(in a whole array) then output false not in not in every itaration. Is it possible to write that in the else statement?

        php arrays string foreach strpos
        Original Q&A
        1

        There are 1 best solutions below

        0
        Melvin Melvin On 24 May 2022 at 12:21

        Sure. You can set a flag whenever you reach the else-statement and check the flag after the for-loop. Something like that:

                        <?php
                        $flag = true;
                        foreach($jobIcons as $jobsKeys){
                            if (stripos($job['title'], $jobsKeys['title']) !== false) {
                               echo "<li class='list-group-item'><img src=".$jobsKeys['image']." style='width: 25px;'> ". $job['title'] ." <span class='badge badge-primary badge-pill'>14</span></li>";
                            }else{
                                $flag = false;
                            }
                        }
                        if (!$flag) { echo "false"; }
                        ?>
        

        This is not that elegant because you set the flag every time you encounter the else-statement but it is acceptable for your case I think.

        Related Questions in PHP

        • How to add the dynamic new rows from my registration form in my database?
        • Issue in payment form gateway
        • How to create a facet for WP gridbuilder that displays both parent and child custom fields?
        • Function in anonymous Laravel Blade component
        • How to change woocomerce or full wordpress currency with value from USD to AUD
        • General questions about creating a custom theme Moodle CMS
        • How to add logging to an abstract class in php
        • error 500 on IIS FastCGI but no clue despite multiple error loggings activated
        • Composer installation fails and reverts ./composer.json and ./composer.lock to original content
        • How to isolate PHP apps from each other on a local machine(Windows or Linux)?
        • Laravel: Using belongsToMany relationship with MongoDB
        • window.location.href redirects but is causing problems on the webpage
        • Key provided is shorter than 256 bits, only 64 bits provided
        • Laravel's whereBetween method not working with two timestamps
        • Implementing UUID as primary key in Laravel intermediate table

        Related Questions in ARRAYS

        • How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
        • What does: "char *argv[]" mean?
        • How to populate two dimensional array
        • User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
        • Function is returning undefined but should be returning a matched object from array in JavaScript
        • The rules of Conway's Game of Life aren't working in my Javascript version. What am I doing wrong?
        • Array related question, cant find the pattern
        • Setting the counter (j) for (inner for loop)
        • I want to flip an image (with three channels RGB) horizontally just using array slicing. How can I do it with python?
        • Numpy array methods are faster than numpy functions?
        • How to enter data in mongodb array at specific position such that if there is only 2 data in array and I want to insert at 5, then rest data is null
        • How to return array to ArrayPool when it was rented by inner function?
        • best way to remove a word from an array in a react app
        • Vue display output of two dimensional array
        • Undot Array with Wildcards in Laravel

        Related Questions in STRING

        • What does: "char *argv[]" mean?
        • User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
        • JSON Body is Not Passing Certain Strings
        • Regex to match repeated substring in Google Sheets
        • Find the sum of the numbers in the sequence
        • Hello, how can I use a block parameter of withstyle parameter when we create a annotated string in jetpackpack compose
        • How to convert an HTML string to an escaped one?
        • Quintic Number Number Counting Hash Function
        • From Buffer("string", "hex) to string JS
        • Calling ToString with a nominated format returns Char rather than String
        • How to update an already existing array by accessing it by a variable with the exact same name assigned to it
        • Why does \b not interpreted as backslash in this regular expression
        • Python: why aren’t strings being internalized if they are received from ints by using str()?
        • If the element(s) in the first list equal element(s) of the second list, replace with element(s) of the third list
        • About Suffix Trees features

        Related Questions in FOREACH

        • How to use nested ForEach-Object
        • jQuery - Click and enable Button without affecting other foreach Laravel arrays
        • Java get objects elements from List<Objects> and add to new ArrayList
        • How to pass once the full dataset to one worker and specific subsets to the other workers in foreach loop using isplit()
        • Stored Procedure to Update Column in TableA to TableB Value +1 For Each Change In The Column
        • Exporting the data from DB by passing the data from input csv file and saving the results in csv file
        • passing object to a view within a foreach loop in CodeIgniter
        • Foreach + If function in Powershell not properly removing items from array
        • OrderBy with lambda?
        • Function for finding multiple values from an array and replace data in a specific column based on the matching IDs?
        • Is JavaScript forEach slower than for loops even in Mozilla Rhino?
        • How to replace non-standard "for each" received from Visual C++ users
        • How can I reset a counter within each subfolder level in a loop that access recursively a parent directory?
        • How to insert user_id (from DB) and imported data (excel file upload) simultaneously?
        • Issue while displaying "foreach" values

        Related Questions in STRPOS

        • Check if array elements exist in another nested array, and remove those that do not
        • Why is php strpos to determine if text is contained in another string not working?
        • simplehtmldom returning span plaintext is not handled as string
        • PHP Function to redirect based on time and day
        • get everything between specific string php
        • Error message: Deprecated Functionality: strpos(): Passing null to parameter #1 ($haystack)
        • Strpos not getting the correct result in condition
        • Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
        • How to find substring position in bytes in Python?
        • Check if the JSON string contains a value and give back the SKU
        • i have faced a problem in search for arabic work inside an array
        • preg_match VS. stripos in PHP
        • How to don't output false in every itaration
        • Delete string between strings and replace with text plus counter
        • strpos works with php 8.1 not php 7.2

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates