I am trying to display an array or arrays in my view and I am having difficulties on how to do it, so any help will be much appreciated :)
My array of arrays in the model:
$user = array();
...
$user[$id] = array(
'id' => $userId[$id],
'match' => $percentage
);
return array('userInfo' => $user);
that stores info from some users. I am passing it to the controller and from there to the view where I want to display the information in $user array. In the array can be one or many users.
here is my controller:
$result = $this->model->getUserDetails();
$this->load->view('view', array('user' => $result);
in the view I want to print the info but I do not know how to do it since I have never worked with arrays of arrays and I am a bit confused.
here is the view:
<?php foreach ($user['userInfo'] as $index => $value) {
echo $value[$index]['id'].' '.$value[$index]['match'];
?>
if I do it this way
or
echo $value['id'];
or
echo $index['id'];
the view displays nothing or doesn't like the 'id' index
this is what I have for
var_dump($result);
array(1) { ["result"]=> array(1) { [0]=> array(11) {
["id"]=> string(2) "55"
["fname"]=> string(6) "Dan" ["lname"]=> string(5) "Re"
["email"]=> string(18) "[email protected]" ["username"]=> string(6) "dan"
["gender"]=> string(4) "Male" ["DOB"]=> string(10) "1990-07-13"
["profile_image"]=> string(8) "dan.jpg"
["short_des"]=> string(147) "I love singing and playing music"
["pwd"]=> string(4) "dan" ["confirm_pwd"]=> string(4) "dan" } } }
meaning that there is one user to be displayed
Pls do help as I am very confused.
Thank you very much.
var_dump($result);to your question.var_dump($result);