array element not being traced by conditional statements but

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pbvamsi
Forum Newbie
Posts: 3
Joined: Fri Jan 27, 2012 2:44 am

array element not being traced by conditional statements but

Post by pbvamsi »

I'm not able to trace 'not out' string with conditional statement. Instead it is not being even traced by array search methods. But I can find the element when I print it like

Code: Select all

var_dump($sections[7][5]);
when I try to trace it by conditional statements I fail to extract it. All I wanna do is to return those batsmen name who are not out.

Code: Select all

<?php
ob_start();
$url = 'http://m.cricbuzz.com/cricket-archive/scorecard/10777/1';
$dom = new DOMDocument;
@$dom->loadHTMLFile($url);
$tds = $dom->getElementsByTagName('td');
foreach ($tds as $td) 
{
echo $td->nodeValue, PHP_EOL;
}
$page = ob_get_contents();
ob_end_flush();
$fp = fopen("output.html","w");
fwrite($fp,$page);
fclose($fp);
$pieces = explode("Bowler", file_get_contents('output.html', FILE_IGNORE_NEW_LINES));
$zaq = explode("\n", $pieces[0]);
unset($zaq[0],$zaq[1],$zaq[2],$zaq[3],$zaq[4]);
 for($i=0;$i<count($zaq);$i++)
 {
 if ($zaq[$i]=='') { unset($zaq[$i]); echo 'reached here..  '; }
  } 
foreach($zaq as $value) 
{
echo '<br>the next elemnt is..        '.$value.'<br>';
} 
$sections = array_chunk($zaq, 6);
  var_dump($sections[7][5]);
 echo array_search('not out', $sections);
 print_r(array_values($sections));
 print_r(array_keys($sections)); 
 echo array_key_exists('not out', $search_array);
 for($i=0;$i<count($zaq);$i++)
{
echo $sections[$i][5].'<br>..';
echo count($sections[$i][5]);
$as=count($sections[$i][5]);
if($sections[$i][5]==="'not out") 
{
 echo count($sections[$i][5]);
 echo $sections[$i][5];
 var_dump($sections[$i][5]);
 }
} 
?>
thanks in advance :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: array element not being traced by conditional statements

Post by social_experiment »

Code: Select all

if($sections[$i][5]==="'not out") 
I'm not sure what the output should look like but try removing the ' from the comparison above
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply