Welcome Guest, Not a member yet? Register   Sign In
[Solved] Foreach loop Not Working
#1

(This post was last modified: 06-04-2016, 04:46 AM by wolfgang1983.)

I have my two arrays but cannot get them to work in my foreach loop

I get error

A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'href'
Filename: common/Header.php
Line Number: 28

How to make i work properly



PHP Code:
<?php

class Header extends MX_Controller {

    public function 
__construct() {
        
parent::__construct();
    }

    public function 
index() {
        
$data['csslinks'] = array();

        
// Bootstrap
        
$csslinks = array(
     
       'href'  => 'app/modules/admin/plugins/bootstrap/dist/css/bootstrap.css',
     
       'rel'   => 'stylesheet',
     
       'type'  => 'text/css',
        );

        
// Custom
        
$csslinks = array(
     
       'href'  => 'app/modules/admin/stylesheets/custom.css',
     
       'rel'   => 'stylesheet',
     
       'type'  => 'text/css',
        );

        foreach (
$csslinks as $csslink) {
            
$data['csslinks'][] = array(
                
'href' => $csslink['href'], // Line 28
                
'rel' => $csslink['rel'],
                
'type' => $csslink['type']
            );
        }

        return 
$this->load->view('common/header_view'$data);
    }



View


Code:
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <base href="<?php echo base_url();?>" />
    <?php foreach ($csslinks as $csslink) {?>
        <link rel="<?php echo $csslink['rel'];?>" type="<?php echo $csslink['type'];?>" href="<?php echo $csslink['href'];?>">
    <?php } ?>
</head>
<body>
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
[Solved] Foreach loop Not Working - by wolfgang1983 - 06-04-2016, 03:38 AM
RE: Foreach loop Not Working - by pdthinh - 06-04-2016, 04:26 AM
RE: Foreach loop Not Working - by wolfgang1983 - 06-04-2016, 04:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB