Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP array_search not working
    primarykey
    data
    text
    <p>Hey guys and girls, i'm stumped. Trying to get array_search to work with this script. </p> <pre><code> &lt;?php $dir = '/var/www/html/pay.group.com/upload'; $i = 0; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != "." &amp;&amp; $file != ".."){ //convert files from pdf to text exec("pdftotext /var/www/html/pay.group.com/upload/" . $file . " /var/www/html/tmp/converted/" . $file); //create array from text files $current_array = file("/var/www/html/tmp/converted/" . $file) or die ("&lt;br/&gt;**cannot find file to create array**"); //search array echo array_search('EMPLOYEE NO. ',$current_array); $i++; echo var_dump($current_array); } } closedir($dh); echo "$i files processed"; } } ?&gt; </code></pre> <p>I get nothing from the array_search and I can't figure out why, its driving me mad. </p> <p>Here is a relevant part of the var_dump that is working correctly. </p> <pre><code>"NON NEGOTIABLE " [28]=&gt; string(5) "9871 " [29]=&gt; string(13) "EMPLOYEE NO. " [30]=&gt; string(1) " " [31]=&gt; string(3) "01 " [32]=&gt; string(6) "SHIFT " [33]=&gt; string(1) " " [34]=&gt; string(4) "MIC " [35]=&gt; string(19) "LOCATION HRS/UNITS " </code></pre> <p>Is there something I am doing wrong? The string for the array search is exactly the same as it is in the actual array so I can't figure out why its not returning an array index for me.</p> <p>Using the pre tag, this is what I get. </p> <pre><code> [27]=&gt; string(15) "NON NEGOTIABLE " [28]=&gt; string(5) "9871 " [29]=&gt; string(13) "EMPLOYEE NO. " [30]=&gt; string(1) " " [31]=&gt; string(3) "01 " [32]=&gt; string(6) "SHIFT " [33]=&gt; string(1) " " [34]=&gt; string(4) "MIC " [35]=&gt; string(19) "LOCATION HRS/UNITS " [36]=&gt; string(1) " " </code></pre>
    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