Home>

Use the following code to convert "100 lines" of data$cLrowsIt is stored in.

$cLrows [] = array (
  'num' =>$gtNum,
  'clss' =>$gtClss,
  'name' =>$gtName,
  'pos' =>$gtPost
  );


At this time, loop processing for 100 lines (* changes each time) is performed.'num' is the same as $ssAt that time

$sclss ='clss' =>$gtClss
  $sname ='name' =>$gtName
  $spos ='pos' =>$gtPost


How can I assign it to the variable set as?

What I tried

Here's the code I tried and didn't like:

foreache ($cLrows as $rows) {
  foreach ($rows as $data) {
    if ($SS = $data [0]):
      $sclss = $data [1];
      $sname = $data [2];
      $spos = $data [3];
    endif;
  }
}
foreache ($cLrows as $rows) {
  foreach ($rows as $k =>$v) {
    if ($SS = $k [$v [0]]):
      $sclss = $k [$v [1]];
      $sname = $k [$v [2]];
      $spos = $k [$v [3]];
    endif;
  }
}
while ($ss == $cLrows [0]):
  $sclss = $cLrows [1];
  $sname = $cLrows [2];
  $spos = $cLrows [3];
endwhile;
php
  • Answer # 1

    It's based on the first code I tried, but how about this code?

    foreach ($cLrows as $rows) {
        if ($SS == $rows ['num']) {
            $sclss = $rows ['clss'];
            $sname = $rows ['name'];
            $spos = $rows ['pos'];
        }
    }