Jump to content

schizoman

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Everything posted by schizoman

  1. In the original loops, I'm accessing $pqPhrase["terms"] and not $pqPhrases["terms"]. While I was trying to figure out why the last phrase was being dropped, I switched to printing out the terms in $pqPhrases to verify the change wasn't just in the way $pqPhrase was being handled. I will be using $phPhrase, and NOT $pqPhrases in the actual code. I access $pqPhrases in the foreach loop for debugging purposes ONLY. To my point: $pqPhrase should in no way, shape or form alter $pqPhrases. If I wanted to alter the "terms" fields in $pqPhrases, I could use &$pqPhrase. For some reason, the contents of $pqPhrases IS being altered within the foreach loop. Since my OSOMTBUFDB (Offensive, Stupid, Only Meant To Be Used For DeBugging) code is getting in the way, I'll offer this up: echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; foreach($pqPhrases as $pqPhrase) { } echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; Output: camaro - doberman - little green buddha with pink nose camaro - doberman - doberman By the way, MikeDean89 asked for me to post what I'm actually trying to do. Here's a simplified version: $rows=""; $row="<tr><td>Your Search Term: ^term^</td></tr>\n"; foreach($pqPhrases as $pqPhrase) { $rows .= str_replace("^term^",$pqPhrase["terms"],$row); } echo $rows; The output: <tr><td>Your Search Term: camaro</td></tr> <tr><td>Your Search Term: doberman</td></tr> <tr><td>Your Search Term: doberman</td></tr> So, while everyone was obsessing on the hubris of accessing $pqPhrases within my foreach loop, I continued to search for an answer, and found this: http://schlueters.de/blog/archives/141-References-and-foreach.html KevinM1 is absolutely correct when he says I have an earlier foreach loop where I'm sanitizing each term and adding it to a mySQL table. Until I read the article at the above link, I would never have expected the resulting behavior, so didn't mention the previous loop. By adding a line to my code before I execute the foreach loop, the expected results were achieved: echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; unset($pqPhrase); // get rid of the offending pointer foreach($pqPhrases as $pqPhrase) { } echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; Output: camaro - doberman - little green buddha with pink nose camaro - doberman - little green buddha with pink nose I apologize for any confusion my original post created, but I'd been trying to debug the code for awhile before posting here, and what I was trying to do within the foreach loop seemed completely irrelevant to what the foreach loop was doing to my array. Printing out the contents of $pqPhrases[$x]["terms"] within the foreach loop was meant to illustrate how $pqPhrases was being changed during each iteration. Hope this clears things up, and hope the link helps anyone else who finds their arrays being altered by a seemingly simple foreach.
  2. No, it's not. I'm echoing the contents of $pqPhrases within the loops to illustrate how the contents are being changed in the original array.
  3. Hi. A quick look at the source code from the link you provided shows what I think is the problem. The play list is generated by Javascript stored in separate files, and the links to those files are relative: <script type="text/javascript" src="/scripts/cookiemonster.js"></script> <script type="text/javascript" src="/scripts/ads.js"></script> <script type="text/javascript" src="/scripts/mini.js"></script> <script type="text/javascript" src="/scripts/pls.js"></script> Basically, the code you're generating is looking for the files on your server, not the Live365 server. Hope this helps.
  4. Okay, I'm going nuts here. I have a (nested) array of search terms that I'm working with. When I run a foreach loop on it, things go bad. Here's a test loop I ran: echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; foreach($pqPhrases as $pqPhrase) { echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; } Output (emphasis added): doberman - camaro - little green buddha with pink nose doberman - camaro - doberman doberman - camaro - camaro doberman - camaro - camaro If I switch to a "for" loop, the results are as expected: echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; for($x=0;$x<count($pqPhrases);++$x) { echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; } Output: doberman - camaro - little green buddha with pink nose doberman - camaro - little green buddha with pink nose doberman - camaro - little green buddha with pink nose doberman - camaro - little green buddha with pink nose The other thing I tried was to redefine a simplified array, which also gives results that are expected: $pqPhrases=array(); $pqPhrases[0]["terms"]="camaro"; $pqPhrases[1]["terms"]="doberman"; $pqPhrases[2]["terms"]="little green buddha with pink nose"; echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; foreach($pqPhrases as $pqPhrase) { echo $pqPhrases[0]["terms"]." - ".$pqPhrases[1]["terms"]." - ".$pqPhrases[2]["terms"]."<br>"; } Output: doberman - camaro - little green buddha with pink nose doberman - camaro - little green buddha with pink nose doberman - camaro - little green buddha with pink nose doberman - camaro - little green buddha with pink nose I'm thoroughly flumoxed. I can't figure out why the first example doesn't work. Am I missing something obvious here? Can anyone help?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.