0

i'm trying to remove some array from foreach example for "result" array :

    $result= array (  
  "1"  => array(
    "nickname" => "Jow",
    "Age"=> "19"
    ),
        "2"  => array(
    "nickname" => "Rayan",
    "Age"=> "25"
    ),
        "3"  => array(
    "nickname" => "Jinx",
    "Age"=> "21"
    ),
    );

i want remove array 1 by nickname mycode :

foreach ($result as $client => $value){

if ( $value["nickname"] == "Jow"){

    unset($result[$client]);

    }
echo $value["nickname"].'<p>';

}

Eventually i want The remaining names like Rayan and Jinx

5
  • check out array_filter Commented Apr 29, 2016 at 6:56
  • 1
    @RodrigoDuterte Oi! You're here. Election is near. Is change really coming? Commented Apr 29, 2016 at 6:58
  • 1
    @rhavendc yes change is really coming Commented Apr 29, 2016 at 7:02
  • @suibber remove array 1 by name Commented Apr 29, 2016 at 7:03
  • @RodrigoDuterte i not understand what you say and i test echo (array_filter($resultt,"Jow")); Commented Apr 29, 2016 at 7:04

2 Answers 2

1

use array_filter ?

$result= array (  
  "1"  => array(
    "nickname" => "Jow",
    "Age"=> "19"
    ),
        "2"  => array(
    "nickname" => "Rayan",
    "Age"=> "25"
    ),
        "3"  => array(
    "nickname" => "Jinx",
    "Age"=> "21"
    ),
);

$arr = array_filter($result, 'filter_by_name');
var_dump($arr);exit;

function filter_by_name($value){
	if ($value['nickname']=='Jow') {
		return false;
	} else {
		return true;
	}
}

Sign up to request clarification or add additional context in comments.

1 Comment

or just return $value['nickname'] != 'Jow''
0

Are you looking for something like this?

function removeByNickName($nickName, $array)
{
    $temp = array();
    foreach($array as $index => $ar)
    {
        if($array['nickname'] != $nickName) array_push($temp, $ar);
    }
    return $temp;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.