Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
share|improve this question
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. – Felix Kling Feb 15 '11 at 16:28

3 Answers

up vote 0 down vote accepted

Try the following:

foreach(array_diff_assoc($x ,$member) as $item)
{
    echo $item;
}
share|improve this answer
Oh GOD its working !!!!!!! Thanxxxxx ALOT !! – Wazan Feb 15 '11 at 16:45
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` – Wazan Feb 15 '11 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. – RobertPitt Feb 15 '11 at 19:27
this $member value is im passing through hidden value as echo "<input type='hidden' value='$member' name='member[]'>"; – Wazan Feb 15 '11 at 19:28

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.

share|improve this answer
Use var_export() for valid PHP code. – Ghpst Feb 15 '11 at 16:31
Now I have a problem on Merge 2 Arrays !! – Wazan Feb 15 '11 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; } ?> – Wazan Feb 15 '11 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. – Marc B Feb 15 '11 at 19:03
Is it!! i try without put serialize and come to u .. – Wazan Feb 15 '11 at 19:06
show 1 more comment
print_r(array_diff_assoc($x ,$member));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.