这个问题已经有了答案:
Problem with: Fatal error: [] operator not supported for strings in
3个答案
对于这段代码,我得到一个错误。
php致命错误:字符串不支持[]运算符
$sname=数组();
$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++;
    }
}

最佳答案

WORKING DEMO

$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'使用行我已经注释掉了

07-28 02:45