thesoggycow Posted May 14, 2008 Share Posted May 14, 2008 Hi Everyone, I'm having trouble with a section of my script... Here it is function getloc($data, $email) { foreach ($data as $i => $value) { if ($value==$email) { return $i; break; } else { return "moo";} } } $email = "[email protected]"; $data = array([email protected],0,5-13,69.232.189.155,[email protected],0,5-13,69.232.189.155); $loc = getloc($data, $email); $loc should equal 4... But instead equals moo, no matter what. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/105557-solved-function-help/ Share on other sites More sharing options...
Lumio Posted May 14, 2008 Share Posted May 14, 2008 array([email protected],0,5-13,69.232.189.155,[email protected],0,5-13,69.232.189.155) Strings always have to have quotes: array("[email protected]",0,"5-13","69.232.189.155","[email protected]",0,"5-13","69.232.189.155") Link to comment https://forums.phpfreaks.com/topic/105557-solved-function-help/#findComment-540747 Share on other sites More sharing options...
thesoggycow Posted May 14, 2008 Author Share Posted May 14, 2008 Solved... Like Lumio here I don't test the code I post Learned something though... A function can only return a value once... News to me ! Link to comment https://forums.phpfreaks.com/topic/105557-solved-function-help/#findComment-540751 Share on other sites More sharing options...
Lumio Posted May 14, 2008 Share Posted May 14, 2008 Omg sorry... I already knew that, but I didn't see that ^^ Link to comment https://forums.phpfreaks.com/topic/105557-solved-function-help/#findComment-540759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.