Help me in solving CHARGES problem

My issue

No entry for terminal type “unknown”;
using dumb terminal settings.

My code

<?php

// your code goes here
function getCharge($chargeAndParticle, $chargeAndParticleInitial, $chargeAndParticleInitialPosition){
    $charge = 0;
    $distancenew = 0;
    $partilcesDistance = 0;
    $length = count($chargeAndParticleInitial);
    $length2 = count($chargeAndParticleInitialPosition);
    $update = 0;
    for ($z = 0; $z <= $length-1; $z++)
{ 
        for ($x = 0; $x <= $length2-1; $x++)
{ 
    $charge = $chargeAndParticleInitial[$z];
    $partilcesDistance = (int) $chargeAndParticleInitialPosition[$x];
    if($charge == 0  and $partilcesDistance >= 2)
    {
        
        $update = $update + 2;
    }
    else if ($charge == 1  and $partilcesDistance == 1)
    {
         $update = $update + 2;
    }
} 
    
}
echo $update;
}
$testcase =  readline();

for ($i = 0; $i <= $testcase-1; $i++)
{ 
    
    $chargeAndParticle = explode(' ', readline());
    $chargeAndParticleInitial = explode(' ', readline());
    $chargeAndParticleInitialPosition = explode(' ', readline());
    getCharge($chargeAndParticle, $chargeAndParticleInitial, $chargeAndParticleInitialPosition);
    
}

Learning course: 1600 to 1800 difficulty problems
Problem Link: Charges Practice Problem in 1600 to 1800 difficulty problems - CodeChef

@ruk29
plzz refer my c++ code for better understanding of the logic

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n>>k;
	    string s;
	    cin>>s;
	    int cnt=0;
	    for(int i=1;i<n;i++)
	    {
	        if(s[i]==s[i-1])
	        cnt+=2;
	        else
	        cnt++;
	    }
	    while(k--)
	    {
	        int x;
	        cin>>x;
	        if(x==1)
	        {
	            if(x+1<=n)
	            {
	                if(s[x-1]==s[x])
	                {
	                    
	                    cnt--;
	                }
	                else
	                cnt++;
	                if(s[x-1]=='0')
	                    s[x-1]='1';
	                    else
	                    s[x-1]='0';
	            }
	            
	        }
	        else if(x==n)
	        {
	            if(x-1>=0)
	            {
	                if(s[x-1]==s[x-2])
	                {
	                    
	                    cnt--;
	                }
	                else
	                cnt++;
	                if(s[x-1]=='0')
	                    s[x-1]='1';
	                    else
	                    s[x-1]='0';
	            }
	        }
	        else
	        {
	            if(s[x-1]==s[x])
	                {
	                    
	                    cnt--;
	                }
	                else
	                cnt++;
	                if(s[x-1]==s[x-2])
	                {
	                    
	                    cnt--;
	                }
	                else
	                cnt++;
	                if(s[x-1]=='0')
	                    s[x-1]='1';
	                    else
	                    s[x-1]='0';
	        }
	        cout<<cnt<<endl;
	    }
	}
	return 0;
}