PHP Doku:: Alias von implode - function.join.html

Verlauf / Chronik / History: (28) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzTextverarbeitungZeichenkettenString-Funktionenjoin

Ein Service von Reinhard Neidl - Webprogrammierung.

String-Funktionen

<<implode

lcfirst>>

join

(PHP 4, PHP 5)

joinAlias von implode()

Beschreibung

Diese Funktion ist ein Alias für: implode().


2 BenutzerBeiträge:
- Beiträge aktualisieren...
datacompboy at call2ru dot com
21.02.2009 18:43
Very useful function i have using: joinr (join-recursive).
It allows you easy join of multi-level arrays.
For example, if you have
  $intervals = array(array(5, 9), array(11, 15), array(22, 24))
and want to have comma-separated list of dash-separated intervals, just do
  print joinr(array(",","-"), $intervals);

Here is function code:
<?php
   
function joinr($join, $value, $lvl=0)
    {
        if (!
is_array($join)) return joinr(array($join), $value, $lvl);
       
$res = array();
        if (
is_array($value)&&sizeof($value)&&is_array(current($value))) { // Is value are array of sub-arrays?
           
foreach($value as $val)
               
$res[] = joinr($join, $val, $lvl+1);
        }
        elseif(
is_array($value)) {
           
$res = $value;
        }
        else
$res[] = $value;
        return
join(isset($join[$lvl])?$join[$lvl]:"", $res);
    }
?>
manbss at yahoo dot co dot in
10.05.2007 6:38
<?php

$array
= array('lastname', 'email', 'phone');
$comma_separated = join(",", $array);

echo
$comma_separated; // lastname,email,phone

?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)