控制器查看传递数组

So I have this line of code in my controller:

$this->load->view('sampleview',$result);

So when I go into my view and try to echo result, either by foreach or directly writing

print_r($result);

it shows an error that it is an undefined variable.

But when I put the print_r($result); on my controller like this below:

function show()
{
$this->load->view('sampleview',$result);
print_r($result);
}

It would print on my sampleview page where I was redirected. I’m confused why this is happening.

EDIT

The whole controller would be: I have another view which I click an anchor tag with segment(3) as an id. Then I query that id to my model then pass it to another view for display.

$id = $this->uri->segment(3);
$result = $this->model->show($recipe_id);
        if($result!=null)
        {   
            $this->load->view('Admin_recipe_edit',$result);
        }

You $result array will be extracted in your view. if you want as an array, then do it as

$data["result"] = $result;
$this->load->view('sampleview',$data);

Then do print_r($result); in view.

This is how you should have to make a array of data that you want to access on your view

// Your array
$result['Data_Array'] = array(....);
$this->load->view('sampleview',$result);
print_r($result);

Now Access like this in your View Section:

View

print_r($Data_Array);

Dude try to put $result in an array example$view_data['$result']=$result; then load the view exmaple $this->load->view(your_view,$view_data);. and in the view page try to print $result.exmaple print_r($result); .It will work I think so.

In CodeIgniter

$Data['result'] = $ArrayData;
$this->load->view('viewfile',$Data);

In View

print_r($result);