简体   繁体   中英

PHP Last variable in nested foreach loop not showing when echoed

Here is my code:

$criterias = $_POST['criteria'];
$criteriaValue = $_POST['criteriaValue'];
$comments = $_POST['Comments'];

foreach ($criteriaValue as $key => $value ){
  foreach( $criterias as $criteriaValue ){
    if( $criteriaValue == $key ){
      $string1 = $key;
      //echo $string1;
      foreach( $comments as $comment => $comm ){
        if( $string1 == $comment ){
          $string3 = $comm;
          //echo $string3;
        }
      }
    }
  }
  foreach ( $value as $result ){
    $string2 = $result;
    //echo $string2;
  }
  $criteria .= mysql_real_escape_string( $string1 . '|' . $string2 . '|' . $string3 . '|' );
}
echo $criteria;

$criteria will echo string1 and string2. But string3 is blank. When I echo from within the foreach loop $string 3 shows the value.

I really appreciate everyone's help!! I think this is probably simmple but I have beaten my head.

You are using mysql_real_escape_string function over $string3 at the end. Try to echo $string3 without applying any filter function.

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