scrubbicus Posted June 1, 2009 Share Posted June 1, 2009 So I'm trying to create a dynamic form and what I need to do is this for instance. Here's the array [0] => 'name', [1] => 'email', [2] => 'select(day-sun-mon-tues-wed-thurs-fri-sat)' What I want to do is to grab [2] out and put it as a string. However I don't want to have to do this $day = array[2]; I want to be able to search the array for characters in this instance would be select and then once it find the characters select it would pull that array item out and I can then make it a string. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 1, 2009 Share Posted June 1, 2009 Ever used a foreach loop before? strpos is another you should use. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 1, 2009 Share Posted June 1, 2009 What you are describing sounds like a pretty poor implementation that is not very flexible as you cannot have fields with similar names/values else you would get unintended matches. Oh well, based upon what you describe, this should work: <?php function returnPartialMatch($array, $search) { //Iterrate through each value in array foreach($array as $value) { //If value has search string, return value if(strpos($value, $search)!==false) { return $value; } } //No match return false return false; } ?> Quote Link to comment Share on other sites More sharing options...
scrubbicus Posted June 1, 2009 Author Share Posted June 1, 2009 Oh crap your right I could have just done that... so I'd probably do a foreach loop on my array and then use a string function to search for 'select' and if the strpos() returns true make that array item another string. Thanks. I also have one more question that just arose. Is there anyway through PHP to grab all $_POST globals that were submitted and put them into a string or array without directly asking for them? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted June 1, 2009 Share Posted June 1, 2009 $_POST globals that were submitted and put them into a string or array $_POST is already an array. Why exactly do you not want to have to use the array indexes? It sounds like you're solving something the wrong way. Quote Link to comment 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.