Jump to content

I need to grab a specific array item without using key and value


scrubbicus

Recommended Posts

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.

Link to comment
Share on other sites

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;
}


?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

$_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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.