Note that there are some explanatory texts on larger screens.

plurals
  1. POstrripos array of needles inside a parent foreach loop
    primarykey
    data
    text
    <p>I'm inside a foreach loop from a scandir() wheres the directory files are <code>$files as $file</code>. I'm trying to simplify my strripos filetype exclusions by using an array of needles, rather than passing several strripos lines for each filetype. </p> <p>This works:</p> <pre><code>if ($code !== 'yes'){ $excluded = strripos($file, '.js') || strripos($file, '.pl') || strripos($file, '.py') || strripos($file, '.py') || strripos($file, '.rb') || strripos($file, '.css') || strripos($file, '.php') || etc.; } else { $excluded = ''; } </code></pre> <p>But this does not:</p> <pre><code> if ($code !== 'yes'){ $exclusions = array('.js, .pl, .py, .rb, .css, .php, etc.'); foreach($exclusions as $exclude){ $excluded = strripos($file, $exclude); } } else { $excluded = ''; } </code></pre> <p><code>$code</code> is a shortcode attribute defined by the user as 'yes' or anything else = no.</p> <p>Then when I get to the output, I check if <code>$excluded</code> has been defined as 'yes.' Like I said, it works with the first example, but I can't get an array to work. To reiterate, I'm already inside the <code>$file</code> loop from the <code>scandir()</code>.</p> <p><strong>UPDATE</strong></p> <p>Tried using <code>in_array</code> but I'm probably doing something wrong. I've tried:</p> <pre><code>$exclusions = array('.js', '.pl', '.py', '.rb', '.css', '.php', '.htm', '.cgi', '.asp', '.cfm', '.cpp', '.dat', '.yml', '.shtm', '.java', '.class'); $excluded = strripos($file, (in_array($exclusions))); </code></pre> <p>And I've tried:</p> <pre><code>$excluded = strripos($file, (in_array('.js', '.pl', '.py', '.rb', '.css', '.php', '.htm', '.cgi', '.asp', '.cfm', '.cpp', '.dat', '.yml', '.shtm', '.java', '.class'))); </code></pre> <p>No go.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload