php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12528 array_unique function changed
Submitted: 2001-08-02 05:39 UTC Modified: 2001-09-14 19:42 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: jinn at magiclamp dot f2s dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.6 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jinn at magiclamp dot f2s dot com
New email:
PHP Version: OS:

 

 [2001-08-02 05:39 UTC] jinn at magiclamp dot f2s dot com
My ISP recently upgraded from 4.0.3pl1 to 4.0.6 - i have a script that runs an 'array_unique' on a 2d array.  This used to work previously, but now it reduces the array down to a single item.

Here is the section of script:
// CLEAN UP DUPLICATES THAT DON'T HAVE THE DESCRIPTION, BUT ARE THE SAME SECTION
				if ( $debug ) echo "<P style='text-align:left'><B>CLEAN UP DUPLICATE SECTIONS</B><BR>
														<I>[\$idx,\$count]...</I><BR>";
				$count = 0;
				for ( $idx = 0; $idx < count($section_result); ++$idx ) {
					$comp1 = strtolower($section_result[$idx][0]);
					$comp2 = strtolower($section_result[$idx+1][0]);
					$comp3 = strtolower($section_result[$idx-1][0]);

					if ( $comp1 == $comp2 ) {
					// IF THIS ENTRY IS THE SAME SECTION AS THE NEXT ONE
						if ( $section_result[$idx+1][1] != '' ) {
							$section[$count][0] = $section_result[$idx+1][0];
							$section[$count][1] = $section_result[$idx+1][1];
							++$count;
						} elseif ( $section_result[$idx][1] != '' ) {
							$section[$count][0] = $section_result[$idx][0];
							$section[$count][1] = $section_result[$idx][1];
							++$count;
						}
					} elseif ( $comp1 != $comp3 ) {
						$section[$count][0] = $section_result[$idx][0];
						$section[$count][1] = $section_result[$idx][1];
						++$count;
					}
					if ( $debug ) echo "[$idx,$count] " . $section[$count-1][0] . " -- " . $section[$count-1][1] . "<BR>";
				} // close for

				if ( $debug ) echo "</P>";

				$section = array_unique($section);

				if ( $debug ) {
					echo "<P style='text-align:left'><B>UNIQUE SECTIONS AFTER CLEAN-UP</B><BR>";
					echo "section count: " . count($section) . " | $count<BR>";
					echo "<I>Work it thru a 'for' loop:</I><BR>";
					for ( $idx = 0; $idx < $count; ++$idx ) {
						echo $section[$idx][0] . " -- " . $section[$idx][1] . "<BR>";
					}
					echo "<I>Work it thru a 'foreach' loop:</I><BR>";
					foreach ( $section as $message ) {
						echo $message[0] . " -- " . $message[1] . "<BR>";
					}
					echo "</P>";
					echo "<P style='text-align:left'><B>UNIQUE SECTION_RESULT AFTER CLEAN-UP</B><BR>";
					foreach ( $section_result as $message ) {
						echo $message[0] . " -- " . $message[1] . "<BR>";
					}
					echo "</P>";
				}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-14 19:39 UTC] jeroen@php.net
Array_unique isn't supposed to handle multi-dimension strings, nor objects.

See also 10658


 [2001-09-14 19:42 UTC] jeroen@php.net
Err: Array_unique/array_diff/array_intersect isn't supposed to handle multi-dimension _arrays_, nor objects.

See also 10658

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 11:01:31 2025 UTC