0

Here this is my code...

<?php 
include("db.php");
    $team_id=$_GET['team_id'];
    $sql1=mysql_query("select members from team where team_id='$team_id'");
    $sql=mysql_query("select user_id from users where school_id= '1'"); 

    while($array=mysql_fetch_assoc($sql))
        {
            $x[] = $array['user_id'];

        }

    echo "<hr/>";

    foreach($x as $tem){
            echo $tem;
            echo "  ";
    }
    echo "</br>";
    $row1=mysql_fetch_array($sql1);
    $member=unserialize($row1['members']);
    echo array_diff_assoc($x ,$member);

    echo "</br>";
        foreach($member as $tem){
                echo $tem;
                echo "  ";
        }
?>

and I'm receiving the output as

1 5 11 12 13 14 15 16 17 18 19 20
Array
15 16 17 18 19 20 

I don't know why im recieving like Array. I want to receive the different values as

1 5 11 12 13 14
1
  • 3
    You cannot echo an array. You will always get Array if you echo it. For debugging, use print_r(). For production, loop over the array and generate appropriate output. Commented Feb 15, 2011 at 16:28

3 Answers 3

0

Try the following:

foreach(array_diff_assoc($x ,$member) as $item)
{
    echo $item;
}
3
  • I have a problem in merge arrays.. <? include("db.php"); $mem=$_POST['mem']; $member=$_POST['member']; $members = array_merge ($member, $mem); ?> but an error msg showing ` Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\AppServ\www\teen\ad_team_mem_db.php on line 5` Commented Feb 15, 2011 at 19:26
  • You would need to create a new question for this, and if my answer helped you, its customary to click the tick to the left of the answer to mark it as the correct answer for the question. Commented Feb 15, 2011 at 19:27
  • this $member value is im passing through hidden value as echo "<input type='hidden' value='$member' name='member[]'>"; Commented Feb 15, 2011 at 19:28
0

array_diff_assoc returns an array, which you're echoing out. try print_r() or var_dump() instead of echo to view the array's contents.

4
  • Now I have a problem on Merge 2 Arrays !! Commented Feb 15, 2011 at 19:01
  • <? include("db.php"); $mem=serialize($_POST['mem']); $member=serialize($_POST['member']); $members = array_merge ($member, $mem); foreach($mem as $item) { echo $item; } ?> Commented Feb 15, 2011 at 19:01
  • Why are you serializing the arrays? that turns arrays into strings. you can't 'array merge' strings. Serializing should be the VERY LAST thing you do. Commented Feb 15, 2011 at 19:03
  • When I remove the serialize method nw it showing an error that argument 1 s not an array but i have used the array as echo "<input type='hidden' value='$member' name='member[]'>"; m sending a hidden value here Commented Feb 15, 2011 at 19:13
0
print_r(array_diff_assoc($x ,$member));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.