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

Managing feature creep in GUIs

project-management

Does anyone have any practical suggestions about how to manage feature creep in GUIs?

Update shared libraries without restarting processes

c linux dll shared-libraries

If my process is loading a .so library and if a new version of the library is available is it possible to switch to the new library without doing a process restart ? Or the answer depends on things...