Hello,

I want array in format

$xyz[]=array($key=>'Some value here',$value=>array('value1','value2));

In below code,
I want it in loop by checking if $ManagerGSID value is not in $xyz[] as $key then insert into it. (as key will $ManagerGSID and value will be array ($EmployeeGSID))
again if got the same $ManagerGSID then push $EmployeeGSID to the last of array ($EmployeeGSID,$EmployeeGSID)

But if $ManagerGSID is not in $xyz array then make new entry of it in xyz as key= $ManagerGSID and value as array ($EmployeeGSID)

But how to do it?

    $managers=array();
    //$xyz[]=array($key=>'',$value=>array()); 
    foreach($Skills as $_Skills)
    {
        $EmployeeGSID=$_Skills['uid'];

        //fetch Manager of employee
        $ManagerGSID=helpers::getManager($EmployeeGSID);
        //push manager id in array if it is not already in array
        if (!in_array($ManagerGSID, $managers))
        {
            array_push($managers,$ManagerGSID);
            //array_push($xyz,$key=>$ManagerGSID,$value=>array_merge($value,$EmployeeGSID)); // want here like this
        }
    }
Member Avatar for diafol

Doesn't seem to make much sense to me:

The array setup you want is a straight two item array - a scalar value (key) and then an array of variable length ($value) for each $xyz item.

I'm not sure why you just don't have this structure...

$xyz[$key] = array(...);

For that you could just do:

if(array_key_exists($keyToCheck, $xyz))
{
    if(!in_array($valueToCheck, $xyz[$keyToCheck]))
        $xyz[$keyToCheck][] = $valueToCheck;
}else{
    $xyz[$keyToCheck] = array($valueToCheck);
}

ohh so soilly i am.
thanks for showing me RIGHT way !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.