Note that there are some explanatory texts on larger screens.

plurals
  1. POchecking if a value is present in an array
    text
    copied!<p>I am trying to compare a string with an array to see if the string is present in the array and if so echo 'in array'. I keep only being able to have the echo work as I want with the very last entry in the array.</p> <pre><code>foreach($array as $key =&gt; $value) { foreach($entries as $entry) { if($entry == $value) echo 'in array 1'; } if (in_array($value, $entries)) { echo 'in array 2'; } if(isset($entries[$value])) { echo 'in array 3'; } } </code></pre> <p>the echo for 'in array 1' and 'in array 2' work only on whatever the very last entry in the $entries array is, and the echo for 'in array 3' doesnt work at all.</p> <p>Its probably something stupid but I am not seeing it...</p> <p>edit: </p> <p>here is some examples of the arrays</p> <pre><code>$entries = array(5) { [0]=&gt; string(14) "example text 1" [1]=&gt; string(14) "example text 2" [2]=&gt; string(14) "example text 3" [3]=&gt; string(14) "example text 4" [4]=&gt; string(14) "example text 5" } $array = array(5) { [0]=&gt; string(14) "example text 1" [1]=&gt; string(14) "example text 2" [2]=&gt; string(14) "example text 3" [3]=&gt; string(14) "example text 7" [4]=&gt; string(14) "example text 8" } </code></pre> <p>so now when I do</p> <pre><code>foreach($array as $key =&gt; $value) </code></pre> <p>$value should have the values from my $array and I need to compare each one of those values to see if they are present in my $entries array. If so id like to echo 'in array'</p> <p>edit 2:</p> <p>if it makes a difference my $entries array is being created by file() since the information is coming from a log. Everytime a new file is added, it is logged, then i want to compare incoming files to the log, determine if they have been added already, and if not, add them.</p>
 

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