简体   繁体   中英

how to scroll through array in PHP?

I tried to insert file into array and get a specific result from it.

the array_search() doesn't seem to work.

it looks something like this:

  $filepath = "/etc/log/20151026.log";
  $logs = file($filepath); 
   $lo = array($logs);  
   $search = array_search("username ",$lo);  
   echo $search;

If I echo only the array $lo I get the array displayed, yet I can't search through it.

I also tried to extract the array by pieces but a search would be more convenient for the purpose I need.

Try foreach . It provides an easy way to iterate or scroll over arrays. There are two syntaxes:

foreach (array_expression as $value)     
statement     
foreach (array_expression as $key => $value)    
statement

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM