2

Hi all i have the follow array

Classes\Form_Record Object ( [sent_data:protected] => Array ( [cw6hwgw] => 11 [ezlkp6m] => 11 ) [fields:protected] => Array ( [cw6hwgw] => Array (... 

And trying to read the vaules from cw6hwgw and ezlkp6m

What do i need to get the result in php as we tried [sent_data][0] which dose not work

4
  • Post the full Classes\Form_Record class code. Commented Sep 12, 2017 at 10:32
  • Those are protected properties - you aren't supposed to access them directly. See if there are any accessor methods on the class. Commented Sep 12, 2017 at 10:34
  • may this can help you : stackoverflow.com/questions/9474446/… Commented Sep 12, 2017 at 10:44
  • Possible duplicate of How to get protected property of object in PHP Commented Sep 12, 2017 at 10:46

2 Answers 2

1

if I understand correctly, you have used an array in the array so you should use two foreach loops, or indicate the number in the array for both arrays.

Sign up to request clarification or add additional context in comments.

2 Comments

No, you misunderstand.... those arrays are protected properties of an object instance, this is not nested arrays
o, My bad...so the only thing that comes to mind is to use acces getter method
1

you need to cast the object to array.

sample code:

$my_obj =(object) ['sent_data:protected' => ['cw6hwgw' => 11, 'ezlkp6m' => 11 ]]; echo gettype($my_obj)."\n\n"; $to_array_ = (array) $my_obj; foreach($to_array_['sent_data:protected'] as $k=>$v){ echo "{$k} = $v \n"; } 

2 Comments

interesting when converted to a array i get this and not sent_data:protected Array ( [ * sent_data] => Array ( [cw6hwgw] => 11 [ezlkp6m] => 11 ) and still cannot read it, not sure if the * or space before is invaild print_r ([ * sent_data])
use print_r(get_object_vars($YOUR_OBJECT_VAR)); to get the indexes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.