Crew-Portal Posted December 11, 2007 Share Posted December 11, 2007 How do I take the array <?php $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['PLAYERNAME']['0']['VALUE'] ?> and loop it until it finds a user named $_POST['username']. The way the array works is like <?php $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['PLAYERNAME']['0']['VALUE'] $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['1']['PLAYERNAME']['0']['VALUE'] $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['2']['PLAYERNAME']['0']['VALUE'] // and ect ect using the is_array function so it doesnt loop forever ?> Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/ Share on other sites More sharing options...
Crew-Portal Posted December 11, 2007 Author Share Posted December 11, 2007 Bump! Im sorry I really hate doing a Bump but sometimes when your on a schedual its gotta be done! Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411616 Share on other sites More sharing options...
kenrbnsn Posted December 11, 2007 Share Posted December 11, 2007 Please give us time to read your post. Bumping after 15 minutes is not fair. Wait at least 2 to 3 hours. Ken Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411622 Share on other sites More sharing options...
teng84 Posted December 11, 2007 Share Posted December 11, 2007 maybe explain it better .. how do you want to get info on that array.. Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411628 Share on other sites More sharing options...
rab Posted December 11, 2007 Share Posted December 11, 2007 <?php foreach($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'] as $user) { print $user['PLAYERNAME'][0]['VALUE']."\n"; } ?> Try that. Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411630 Share on other sites More sharing options...
Crew-Portal Posted December 11, 2007 Author Share Posted December 11, 2007 I would like the array to loop itself while is_array() until it finds an array with a value of whatever the user entered whcih can be carried over by a $_POST['username'] Global. I think it would be done like <?php $array = '0'; while (is_array($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$array]['PLAYERNAME']['0']['VALUE'])){ if ($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$array]['PLAYERNAME']['0']['VALUE'] = $_POST['username']){ echo 'Ya!'; else $array++; } } ?> Thats something I just slapped together. It probably wont work though. My real concern is I do not know how to use While loops and I do not know how to stop a loop. Did I do it right? Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411631 Share on other sites More sharing options...
rab Posted December 11, 2007 Share Posted December 11, 2007 ...Why don't you try it... and fyi, foreach loops arrays. Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411634 Share on other sites More sharing options...
teng84 Posted December 11, 2007 Share Posted December 11, 2007 foreach($array as $val){ if(is_array($val)){ foreach($value as $x ){ // do some stuff here $cnt++; if(count($value == $cnt)){ if (is_array($x)){ $value = $x; $cnt = 0; } } } } } not tested but i think this kind of sysntax will work not i guess that is only applicable for single dimensional array Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411638 Share on other sites More sharing options...
Crew-Portal Posted December 11, 2007 Author Share Posted December 11, 2007 wOAH! tHATS COMPLICATED! lol. But it looks like it would work thanks! also you check out my picture by my rank and post count Do you like it. Its how PHP makes me feel sometimes! Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411639 Share on other sites More sharing options...
teng84 Posted December 11, 2007 Share Posted December 11, 2007 where totally diff.. when php screwed me i calm down and take a deep breath. when you have that attitude it will be hard to solve complected problem .. lol Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411642 Share on other sites More sharing options...
Crew-Portal Posted December 11, 2007 Author Share Posted December 11, 2007 Yes but notice the comp doesnt break... lol! Quote Link to comment https://forums.phpfreaks.com/topic/81118-looping-an-array/#findComment-411643 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.