I made an iterative loop and created two matrices and I want when I find a specific name I put the corresponding value from the other row in the J variable but I gave me the wrong result which is the number 8 where the number was supposed to appear 7 // my code:
<?php
include 'DB.php';
$db=DB::getInstance();
//$posts = $db->table('posts')->get();
//echo json_encode($posts);
//$users = $db->table("posts")->Qget();
$rows = $db->table('posts')->get();
$filter_value1 = [];
$filter_value2 = [];
$i=0;
$j=0;
foreach($rows as $row){
$filter_value1[]=$row->name;
$filter_value2[]=$row->user_id;
if($filter_value1[$i]="gmal"){
$j= $filter_value2[$i];
}
// echo "$row->name <br>";
$i++;
}
echo($j);
=
: This is an assignment operator in any Language suppose we want to assign some value to a variable we will use (equal to) = sign. It does not return anything. e.g.$name= "gmal";
==
: This is a comparison operator. If we want to compare two values or values hold by variables we should use==
. This operator returns True /False bases on comparison e.g.if("22" == 22) it will return true
===
: Checks the values as well as the type of operands.if("22" === 22) it will return false
so in your code change the following line
if($filter_value1[$i]="gmal")
to
if($filter_value1[$i] == "gmal")