Rev 23 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 23 | Rev 24 | ||
---|---|---|---|
Line 365... | Line 365... | ||
365 | $aNew[$value] = count($aNew); |
365 | $aNew[$value] = count($aNew); |
366 | } |
366 | } |
367 | return $aNew; |
367 | return $aNew; |
368 | } |
368 | } |
369 | 369 | ||
- | 370 | /** |
|
- | 371 | * Maps an array to another array using a callback function. |
|
- | 372 | * |
|
- | 373 | * Unlike array_map(), the callback is called with three parameters: the value |
|
- | 374 | * to be processed, the key of that value, and the array processed. The return |
|
- | 375 | * value of the callback defines the value for the same key of the returned |
|
- | 376 | * array. |
|
- | 377 | * |
|
- | 378 | * Because of the way the callback is called, this method supports processing |
|
- | 379 | * only one array at a time, unlike array_map(). Unlike array_walk(), this |
|
- | 380 | * function does not modify the original array. |
|
- | 381 | * |
|
- | 382 | * @param string|array $callback |
|
- | 383 | * The callback to be used for mapping array values. If an array, the first |
|
- | 384 | * element of the array is supposed to be the class name, and the second |
|
- | 385 | * element the method name of a static method to be used. |
|
- | 386 | * @param array $array |
|
- | 387 | * The array to process |
|
- | 388 | * @return array |
|
- | 389 | * @see array_map() |
|
- | 390 | * @see array_walk() |
|
- | 391 | */ |
|
- | 392 | function array_map2($callback, $array) |
|
- | 393 | { |
|
- | 394 | $a = array(); |
|
- | 395 | ||
- | 396 | if (is_array($callback)) |
|
- | 397 | { |
|
- | 398 | list($class, $method) = $callback; |
|
- | 399 | } |
|
- | 400 | ||
- | 401 | foreach ($array as $key => &$value) |
|
- | 402 | { |
|
- | 403 | if (is_array($callback)) |
|
- | 404 | { |
|
- | 405 | $a[$key] = $class::$method($value, $key, $array); |
|
- | 406 | } |
|
- | 407 | else |
|
- | 408 | { |
|
- | 409 | $a[$key] = $callback($value, $key, $array); |
|
- | 410 | } |
|
- | 411 | } |
|
- | 412 | ||
- | 413 | return $a; |
|
- | 414 | } |
|
- | 415 | ||
370 | /** |
416 | /** |
371 | * Converts a string or an array of strings to an associative |
417 | * Converts a string or an array of strings to an associative |
372 | * bitmask array with the string(s) as key(s). |
418 | * bitmask array with the string(s) as key(s). |
373 | * |
419 | * |
374 | * Converts the argument to a bitmask array where each member's |
420 | * Converts the argument to a bitmask array where each member's |
Line 470... | Line 516... | ||
470 | return preg_replace('/\s{2,}/', ' ', $s); |
516 | return preg_replace('/\s{2,}/', ' ', $s); |
471 | } |
517 | } |
472 | 518 | ||
473 | function debug($x) |
519 | function debug($x) |
474 | { |
520 | { |
- | 521 | echo '<pre>'; |
|
- | 522 | ||
- | 523 | // if (is_array($x)) |
|
- | 524 | // { |
|
- | 525 | // print_r($x); |
|
- | 526 | // } |
|
- | 527 | // else |
|
- | 528 | // { |
|
475 | echo '<pre>'; var_dump($x); echo '</pre>'; |
529 | var_dump($x); |
- | 530 | // } |
|
- | 531 | ||
- | 532 | echo '</pre>'; |
|
476 | } |
533 | } |
477 | 534 |