#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Get all array in foreach


    Hi not so much experienced wiht php so need help.

    I am trying to get list from array but it is only giving me first array item and not all

    Here is my code

    I am getting this from my database query

    PHP Code:
    Array ( [item] => hotcategoriesactivity 
    below is my foreach loop

    PHP Code:
    $sorted $order;
    echo 
    '<pre>';
    print_r($sorted);
    echo 
    '</pre>';

    $temp_nav = array(); 
    foreach (
    $sorted as $key) { 
        if(isset(
    $navigation[$key])) 
            
    $temp_nav[$key] = $navigation[$key]; 

    $navigation $temp_nav
    echo 
    '<pre>';
    print_r($navigation);
    echo 
    '</pre>'
    $order print_r result is here

    PHP Code:
    Array
    (
        [
    0] => hot
        
    [1] => categories
        
    [2] => activity

    Now result I am getting from print_r($sorted); is as below

    PHP Code:
    Array
    (
        [
    0] => hot
        
    [1] => categories
        
    [2] => activity

    But when I checked in foreach loop it is only outputing only fist item as below

    Below rewsult for $navigation

    PHP Code:
    Array
    (
        [
    hot] = Array
            (
                [
    url] => ./url
                
    [lable] => Hot Items
            
    )

    But I want only value like below

    PHP Code:
    array(
        
    'hot',
        
    'categories',
        
    'activity'

    So how can I write the code so it gives me result with all item but not only first item

    Additional Info:

    When I am write array manually as below
    PHP Code:
    $sorted  = array('hot''categories''activity'); 
    Than this works completely fine.. but not from database query
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,604
    Rep Power
    595
    Since we don't know what $navigation is or how it is initialized, it is hard to help you. It appears from the result that $navigation is an array of arrays. Post the 'print_r($navigation);' output before the loop so we can understand what it is.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0
    Originally Posted by gw1500se
    Since we don't know what $navigation is or how it is initialized, it is hard to help you. It appears from the result that $navigation is an array of arrays. Post the 'print_r($navigation);' output before the loop so we can understand what it is.
    It's done. There was strange issue. I was adding in database with space and that was creating the issue. But now I have some other issue.. will post in new thread as that is different approach..

    Thanks a lot.

IMN logo majestic logo threadwatch logo seochat tools logo