Jump to content

Getting value from array


dreampho

Recommended Posts

Hi.

 

I have the following array:

array(18) { ["category"]=> array(1) { [0]=> string(1) "1" } }

The main array is indexed with $data, so I thought $data['category'][0]; would do the trick to get the value, but it returns NULL.

 

How is the correct way to access to this value?

 

PS. I am able to access other values through $data when there are not multidimensional arrays.

Link to comment
https://forums.phpfreaks.com/topic/283009-getting-value-from-array/
Share on other sites

@cyberRobot.

 

I have starred at this for ages now and just cannot for the life of me see the issue.

 

Here is my full function: (you'll see $data is passed to the function)

    public function entry_submission_end($entry_id, $meta, $data)
    {        
    
        if ($data['channel_id'] == '4') {
                        
            $member_id = $meta['author_id'];
            
            // Find member group for member
            $this->EE->db->select('group_id');
            $this->EE->db->where('member_id', $member_id);
            $query = $this->EE->db->get('exp_members');    
            $member_group = $query->row();
            $member_group = $member_group->group_id;
            $category_id = $data['category'][0];
            
            $type = $data['type'];
            $portfolio_number = 0;
            
            if ($type == '2.0') {
                $type = '2';
            } else {
                $type_split = explode(".", $type);
                $portfolio_number = $type_split[1];
                $type = '1';
            }
    
            $insert = array(
               'entry_id' => $entry_id,
               'member_id' => $member_id,
               'member_group' => $member_group,
               'category_id' => $category_id,
               'type_id' => $type,
               'portfolio_number' => $portfolio_number
            );
            
            $this->EE->db->insert('exp_submissions', $insert);
            
        }
                
    }

If I print out the $data variable, it shows this:

Array ( [RET] => http://www.mydomain.com/account/add-submission [URI] => account/add-submission [XID] => 9c4967c581b38956276d906f84bdd0ea21f3fdaf [return_url] => account/submission-complete/ENTRY_ID [channel_id] => 4 [entry_id] => 0 [ACT] => 4 [meta] => BJ6y4b3z03uiWTtrUJV0Ed+GiBx0qHdfQIyjoMTKwYlIdc6+GXIR2ZafOi1wHEO7TwkV8Vqxa9UHDOfSLGAbqtUDGXBkFWHolOAhGO5815Qy8XEcsVYbAJ6mrt2unT3l0KtjUaY0DtDqkTy5hdlwScNuYXO9IuI4Ts/7E3JgZkRUj0j/YNx4upWAgdGCycPNhS7zN8z5BTfhfEmG/HxgSsh2qL8olN0NpN8gcFLbb+26So3sMhs1ePZ4O2eYtREkaT7LY6OOxncMUXJ0SqZgPvexBOsd1bgaZzOJyuOxDW6clpFTeDvaZ08uxT4dmqpBdDuxzX1uPmSGd1z9M/bwLVdksDo1O/Bqa8BS8vb5mCKbJf4g9o5F4uCZ/Yd8zQryYKLnCJaFLw7BAZoQAHKolyOTr3YBSPlHt0eS3xV+B6UwXnmt5fTrZW+E5PYxhrpyNtcDvKur3D6nf0Jl3UE2ArC2ocN3X9RumWynG6eBdsvSErpVVEf9liN41zW7OoEu/dDJdPWfoqm0EpNtPqimXeuKPnUg8uR9qBGwKhpwlbA= [return] => account/submission-complete/ENTRY_ID [site_id] => 1 [submission_file_hidden_file] => [submission_file_hidden_dir] => 1 [type] => 2.0 [snap_utTEbLXYz] => NBePCXPUaVqYN [submission_file] => {filedir_1}name_name_141.jpg [field_id_48] => {filedir_1}name_name_141.jpg [field_ft_48] => none [revision_post] => Array ( [RET] => http://www.mydomain.com/account/add-submission [URI] => account/add-submission [XID] => 9c4967c581b38956276d906f84bdd0ea21f3fdaf [return_url] => account/submission-complete/ENTRY_ID [author_id] => 12 [channel_id] => 4 [entry_id] => 0 [ACT] => 4 [meta] => BJ6y4b3z03uiWTtrUJV0Ed+GiBx0qHdfQIyjoMTKwYlIdc6+GXIR2ZafOi1wHEO7TwkV8Vqxa9UHDOfSLGAbqtUDGXBkFWHolOAhGO5815Qy8XEcsVYbAJ6mrt2unT3l0KtjUaY0DtDqkTy5hdlwScNuYXO9IuI4Ts/7E3JgZkRUj0j/YNx4upWAgdGCycPNhS7zN8z5BTfhfEmG/HxgSsh2qL8olN0NpN8gcFLbb+26So3sMhs1ePZ4O2eYtREkaT7LY6OOxncMUXJ0SqZgPvexBOsd1bgaZzOJyuOxDW6clpFTeDvaZ08uxT4dmqpBdDuxzX1uPmSGd1z9M/bwLVdksDo1O/Bqa8BS8vb5mCKbJf4g9o5F4uCZ/Yd8zQryYKLnCJaFLw7BAZoQAHKolyOTr3YBSPlHt0eS3xV+B6UwXnmt5fTrZW+E5PYxhrpyNtcDvKur3D6nf0Jl3UE2ArC2ocN3X9RumWynG6eBdsvSErpVVEf9liN41zW7OoEu/dDJdPWfoqm0EpNtPqimXeuKPnUg8uR9qBGwKhpwlbA= [return] => account/submission-complete/ENTRY_ID [site_id] => 1 [title] => Test [submission_file_hidden_file] => [submission_file_hidden_dir] => 1 [type] => 2.0 [category] => Array ( [0] => 7 ) [status] => open [snap_utTEbLXYz] => NBePCXPUaVqYN [submission_file] => name_name_14.jpg [field_id_48_hidden_file] => [field_id_48_hidden_dir] => 1 [field_id_48] => name_name_14.jpg [field_ft_48] => none [allow_comments] => y [entry_date] => 1381930740 [previous_status] => ) )

You'll see towards the end, it shows :

[category] => Array ( [0] => 7 )

This is what I am trying to access.

 

Thank you.

 

P.S The code is for CMS so thats why some of the code includes 'EE->db' etc.

 

Archived

This topic is now archived and is closed to further replies.

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