join() PHP function removes duplicated values?

how are you doing? When I use the join() function with duplicated values in an array, the join function returns the array but removing duplicates and I dont want that!

Example:

$array= array(1, 2, 2, 2);
$res = join(',', $array);

I get this:

1,2

but I want the result to be:

1,2,2,2

Hope someone can help me! Thank you

Answers


You say this is your code:

while ($coordenada = mysql_fetch_assoc($resultado)) {
    $arrayX[$coordenada['ARTICULO']] = $coordenada['ARTICULO'];       
    $arrayY[$coordenada['CANTIDAD']] = $coordenada['CANTIDAD']; 
}

In which case, you are not populating the arrays like you think. Your code is doing this:

$arrayY[1] = 1;
$arrayY[2] = 2;
$arrayY[2] = 2;
$arrayY[2] = 2;

So only contains 2 values. If you want duplicates, change your code to this:

while ($coordenada = mysql_fetch_assoc($resultado)) {
    $arrayX[] = $coordenada['ARTICULO'];          
    $arrayY[] = $coordenada['CANTIDAD']; 
}

use implode: implode(',', $array) even though join is just an alias of implode, it is the proper function to use


Need Your Help

multidimensional (2D) function plot in R

r plot

I'm looking into plotting functions and I've run into persp and curve but I'm not able to follow them to plot a 2D function.

Showing validation errors at top of page with PHP

php forms validation

I've written a Form object (code: http://pastebin.com/U1xMRhdn) that validates whether information entered in a form field is valid or not. An example of it:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.