Hello!
I have html table that are made with foreach.
So what i need is to get all unique values in one array!
I get multiple arrays (seems one array for each line)
what am i doing wrong?
As i have big code will try to make one little just for this
$age is coming from database and is holding also array key example 01
//names array
$names = array(
"18" => "John",
"17" => "Mark",
"19" => "Tod",
);
echo '<table><tr><th>name<th>age</tr>';
$commaList=array();
foreach($names as $key => $value){ //getting all names
foreach($commaList as $val) { //gets only names where age is 18+
$bzzzzz .= $val.','; //i put the names in comma separated list
}
foreach(explode(',', $bzzzzz) as $valz){ // here i check if user form comma separated list == $value
if($value==$valz){
echo'<td>'.$value; if so i echo name
echo '<td>'.$age;
}
}
if($age>18){ // here i check if 18+ add to array to show it in <td> $value ^
array_push($commaList,$value);
}
}
and what about Tod? Where are your filtering this value? $age is undefined in your example. i don’t see what this concat/explode should do. your table cells are broken and not even within a row. give an example of the expected results. comment your code.
i don’t see any relevant change in the code. i don’t see any answer on what i said. i don’t see any use of the provided codebase. i don’t see any problem description for the new code.
What do you actually want to end up with at the end of the routine? You go into it with an array of names and ages, and a variable called $age that comes from your database. If you just want to end up with an array of names and ages where the age is greater than the value of $age, surely that’s simply