Warning: A non-numeric value encountered

后端 未结 18 1636
抹茶落季
抹茶落季 2020-11-22 06:15

Recently updated to PHP 7.1 and start getting following error

Warning: A non-numeric value encountered in on line 29

Here is wha

18条回答
  •  灰色年华
    2020-11-22 06:19

    $sn = 0;//increment the serial number, then add the sn to job
    for($x = 0; $x<20; $x++)
    {
    $sn++;
    $added_date = "10/10/10";
    $job_title = "new job";
    $salary = $sn*1000;
    $cd = "27/10/2017";//the closing date
    $ins = "some institution";//the institution for the vacancy 
    $notes = "some notes here";//any notes about the jobs
    
    $sn_div = "
    ".$sn."
    "; $ad_div = "
    ".$added_date."
    "; $job_div = "
    ".$job_title."
    "; $salary_div = "
    ".$salary."
    "; $cd_div = "
    ".$cd."
    ";//cd means closing date $ins_div = "
    ".$ins."
    ";//ins means institution $notes_div = "
    ".$notes."
    "; /*erroneous line*/$job_no = "job"+$sn;//to create the job rows $$job_no = "
    ".$sn_div.$ad_div.$job_div.$salary_div.$cd_div.$ins_div.$notes_div."
    "; echo $$job_no;//and then echo each job }

    that's the code I had which looped and created new html div elements. The code worked fine and the elements were formed, but i got the same warning in the error_log.

    After reading the useful other answers, I figured that I was summing up a string and a number in the erroneous line. So I changed the code at that line to

    /*erroneous line*/$job_no = "job"&&$sn;//this is the new variable that will create the job rows
    

    Now the code works as earlier but with no warnings this time. Hope this example would be useful to someone.

提交回复
热议问题