1

In my controller i'm using data variable like this

$data['some_var'] = $this->Model->some_info($param);

So if i do var_dump this $data['some_var'] it will print like this

  object(StdClass)[4]
  Public 'blah1' => String 'blah1' (Length=5)
  Public 'blah2' => String 'blah2' (Length=5)
  Public 'blah3' => String 'blah3' (Length=5)
  Public 'blah4' => String 'blah4' (Length=5)

I know how to use this $data[] into view file but i want to use this $data[] into controller file,

What i want , i want to use blah1 from array

I tried like this

$var = $data['some_var']['blah1'];

$var = $some_var->blah1;

I'm not sure how to sort-out this things

Tawhidul Islam
  • 352
  • 4
  • 19

3 Answers3

1

ok try this it will work

$var = $data['some_var'][0]->blah1;
Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
0

Try

$var = $data['some_var']->blah1;
Rana Soyab
  • 898
  • 5
  • 20
0

you might want to try the solution of typecasting your object - answer from Gordon : details here

// typecast your object
$data['some_var'] = (array) $this->Model->some_info($param);

// access the index of the array
// !! this won't work if ['blah1'] contains an Object !!
$var = $data['some_var']['blah1'];

If you want to access sub-object as well I guess you'll have to write a recursive function that will typecast every level see Gordon's answer as well

Community
  • 1
  • 1
Renard Masque
  • 73
  • 1
  • 11