Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:46:55+00:00 2026-06-01T22:46:55+00:00

I have an field name that is passed to me via an ajax function

  • 0

I have an field name that is passed to me via an ajax function which i need to use to lookup values in an existing array. e.g.

$myarray = array(
    'name' => array(
        '0' => array(
            'first' => 'Steve'
        )
    ),
);


$incoming = 'name[0][first]';

So using the $incoming variable i wanted to get the corresponding data out of the array but cant figure out how to convert the string into the array indicies lookup.

Im trying to come up with a method that will work regardless of the level of nesting in the array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:46:56+00:00Added an answer on June 1, 2026 at 10:46 pm

    Suggestion #1

    Change the jQuery to send the request as JSON, which can instantly be converted into a PHP array with json_decode.

    Suggestion #2

    If you can’t switch to JSON, use preg_split to split the incoming field and loop over them to grab the correct array element. Something along the lines of:

    $incoming = 'name[0][first]';
    
    $parts = preg_split('/(\[|\])/', $incoming, null, PREG_SPLIT_NO_EMPTY);
    
    $el = $myarray;
    foreach ($parts as $part) {
        $el = $el[$part];
    }
    
    echo $el; // Steve
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that is passed via ajax and displayed. When the code
i have table called as Support, which have a field named Name and contains
I have a app that searches a database and retrieves 3 fields Name, Email
I have a a gridpanel that has the following fields: Name ID Address Home_Phone
Supposing that I have millions of user profiles, with hundreds of fields (name, gender,
At the moment I have a combobox that is populated from the name fields
I have an input field whose name is an MD5 string e.g.: <input type=hidden
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
It is possible to have whitespace in an Ember.Object 's field name, but how
The Form variable in my form is being passed/retrieved via Session. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.