字符串不支持[]运算符 [英] [] operator not supported for strings

查看:89
本文介绍了字符串不支持[]运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于此代码,我得到了错误。在此行 $ sname [] = $ rs ['StudentId'];
PHP致命错误:[]字符串
不支持运算符$ sname = array();
$ i = 0;

For this code i get the error.at this line $sname[] = $rs['StudentId']; PHP Fatal error: [] operator not supported for strings $sname = array(); $i=0;

foreach($data as $rs){

    foreach($SchoolName as $sname){
//      echo $rs['SchoolName'].'=='.$sname."<br />";
        echo $i."<br />";                  
        if($rs['SchoolName'] == $sname){
            $sname[] = $rs['StudentId'];
        }   
        $i++;  
    }                   
}


推荐答案

< a href = http://codepad.org/Z1zmlr0U rel = nofollow>工作演示

$SchoolNames = Array(10003, "Southwestern College", "National University", "Western Governors University", "Southwestern College Admissions Center - Evaluations Dept");
$data = array(
    0 =>  Array(
        'STU_MANG_fname' => "Jennifer",
        'STU_MANG_lname' => "patel",
        'SchoolName' => "Southwestern College Admissions Center - Evaluations Dept",
        'ShipAddress1' => "900 Otay Lakes Road",
        'ShipState' => "CALIFORNIA" 
    )
);


foreach($data as $studen_info){
    foreach($SchoolNames as $id=>$school_name){
        if($studen_info['SchoolName'] == $school_name){
            $student_names[$school_name] = $id;
            //$student_names[$school_name] = $student_info['StudentId'];;
        }
    }
}

print_r($student_names);

您给我的学生信息数组中没有'StudentId',所以我假设您想使用学生数组的键(如果实际上我已经注释掉了'StudentId'使用行)

there was no 'StudentId' in the student info array you gave me so I assume you want to use the key of the student array if there is in fact a 'StudentId' use line i commented out

这篇关于字符串不支持[]运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆