dreampho Posted October 16, 2013 Share Posted October 16, 2013 (edited) 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. Edited October 16, 2013 by dreampho Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/ Share on other sites More sharing options...
jazzman1 Posted October 16, 2013 Share Posted October 16, 2013 The path to the index is correct - $data['category'][0]. Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/#findComment-1454098 Share on other sites More sharing options...
cyberRobot Posted October 16, 2013 Share Posted October 16, 2013 Perhaps the value is getting reset somewhere. Or maybe there is something else going on. If you need further assistance, we'll need to see some code. Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/#findComment-1454102 Share on other sites More sharing options...
dreampho Posted October 16, 2013 Author Share Posted October 16, 2013 @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. Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/#findComment-1454115 Share on other sites More sharing options...
Solution Ch0cu3r Posted October 16, 2013 Solution Share Posted October 16, 2013 looking at the array structure for $data, The category is within a sub array called revision_post. You'll need to use $data['revision_post']['category'][0] Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/#findComment-1454120 Share on other sites More sharing options...
dreampho Posted October 16, 2013 Author Share Posted October 16, 2013 Oh thank you! I can't believe I missed that! Its strange though that others like the item before can be accessed with $data['type']; Any ideas why? Just to fully understand. Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/#findComment-1454121 Share on other sites More sharing options...
Ch0cu3r Posted October 16, 2013 Share Posted October 16, 2013 (edited) I cant tell you that as I don't how the $data array is being populated. Edited October 16, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/#findComment-1454123 Share on other sites More sharing options...
dreampho Posted October 16, 2013 Author Share Posted October 16, 2013 Okay. Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/283009-getting-value-from-array/#findComment-1454124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.