SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to get value from subarray of this array

    Hi,
    I've an array below which I'd like to retrieve each individual values.
    Code:
    Array(
    	[employee] => id=55&name=John&last_name=Smith,
    	[salary] => 40000,
    	[bonus] => 5000
    );
    I want to extract the first set of data to
    Code:
    	$id = "55";
    	$name = "John";
    	$last_name = "Smith";
    How do I do this?
    Thank you,

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,388
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi ketting00,

    There's a php function called parse_str which can solve this for you:
    PHP Code:
    $array = array(
        
    'employee' => 'id=55&name=John&last_name=Smith',
        
    'salary' => 40000,
        
    'bonus' => 5000
    );

    parse_str($array['employee'], $employee); 
    $employee is now an array of the values from the employee string.

  3. #3
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thank you,

    That helps me a lot.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •