I am newbie in php... there are 4 array which I want to display, but It does not display anything....
Please refer with the code
$new_strip_from_name[] = $strip_from_name;
$new_from_name[] = $from_name;
$new_to_name[] = $to_name;
$new_lastdata[] = $lastdata;
echo "<table style='border: 2px solid black; text-align:left'>";
foreach($new_from_name as $from_name2){
foreach($new_lastdata as $lastdata2){
foreach($new_to_name as $to_name2){
foreach($new_strip_from_name as $key => $value){
if((strpos($lastdata2, $value) !==FALSE)){
echo "<tr>";
echo "<td>$from_name2</td>";
echo "<td>$to_name2</td>";
echo "<td>$lastdata2</td>";
echo "</tr>";
}
}
}
}
}
echo "</table>";
sample array
$new_strip_from_name = array("okay");
$from_name; = array("john", "mar", "jeff");
$to_name; = array("phil", "india", "japan");
$lastdata; = array("john@okay", "mar@okay", "jeff@not");
desired output
john phil john@okay
mar india mar@okay
Okay now we see what you want!! but it wont work like this. The best way would be to create a class for that -> http://php.net/manual/en/language.oop5.basic.php. But here a basic solution which can work:
$messages = array();
$message = array();
$message['from'] = "john";
$message['to'] = "phil";
$message['lastdata'] = "john@okay";
array_push($messages, $message);
Do this for every message or whatever it is and then this:
foreach ($messages as $message){
if (strpos($message,"okay") !== false){
echo "<tr>";
echo "<td>".$message['from']."</td>";
echo "<td>".$message['to']."</td>";
echo "<td>".$message['lastdata']."</td>";
echo "</tr>";
}
}
This anwser should work with your current data structure, but this is NOT clean. It is not the way it should be, you should have 1 element for each message, not 4 arrays with the 4 parts of the message, this could really lead to some serious mixup problems. You should change the collection or creation of the data if possible. But anyhow try this:
$new_strip_from_name[] = $strip_from_name;
$new_from_name[] = $from_name;
$new_to_name[] = $to_name;
$new_lastdata[] = $lastdata;
echo "<table style='border: 2px solid black; text-align:left'>";
for ($i = 0; $i < sizeof($new_from_name); $i++){
if (strpos($new_lastdata[$i],"okay") !== false){
echo "<tr>";
echo "<td>".$new_from_name[$i]."</td>";
echo "<td>".$new_to_name[$i]."</td>";
echo "<td>".$new_lastdata[$i]."</td>";
echo "</tr>";
}
}
echo "</table>";