Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: php array issue

  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php array issue

    Hey all,

    In php I have an included file via "include_once". In that file there is another included file in the same way. In that included file I have a function that creates an array from another function. When I print_r the array, it's correct, and is_array returns true. However, when I run the array_keys function, it outputs an error saying that it's not an array. Anyone else have this issue?

    Thanks!

    -josh

    PS:
    The code
    PHP Code:
    <?php

        
    function arr_val_filt_2_var_pound_ret($v){
            return 
    '###' $v '###';
        }
        function 
    var2child_replace_return($path$text){
            
    $return '';
            if(isset(
    $text)){
                
    $return $text;
                if(isset(
    $path)){
                    
    $var_sig '###';
                    
    $child child_return($path);
                    
    $name array_keys($child);
                    
    $name array_filter($name"arr_val_filt_2_var_pound_ret");
                    
    $text str_replace($name$child$text);
                    
    $return $text;
                }
            }
            return 
    $return;
        }
        
        function 
    child_return($path){
            global 
    $cfh;
            
    $return = array();
            if(isset(
    $path)){
                
    $exceptions = array(
                    
    '.',
                    
    '..',
                    
    'asset',
                    
    'asset_share',
                    
    'edit'
                
    );
                
    $child $cfh->contents($path);
                foreach(
    $child as $key => $value){
                    if(
    $value['type'] == 'dir'){
                        if(!
    in_array($value['name'], $exceptions)){
                            
    $return[$value['name']] = include_once($value['dir'] . '/index.php');
                        }
                    }
                }
            }
            return 
    $return;
        }

    ?>

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Can you show what the print_r had (I'm assuming it was for $child)?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Jay,

    Yes, and thankyou for posting.
    That's what I don't get at all. I can print_r($child) and it prints out
    Array ( [content_0] => 1 )
    but here's the funny thing. After I put in the line print_r($child), the array is recognized, and works just fine for the php afterwards. Really funny insident. I'm thinking it's something about this being a return file once included.

    -josh

  • #4
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i found a fix to the problem. i dont' know why, but I have to change
    $child = child_return($path);
    to
    $child = (array)child_return($path);

    somehow the (array) fixes it like magic. i dont' know why I would have to call this, bc when the function itself is not in an outside included file, it works just fine. odd, very odd


  •  

    Posting Permissions

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