note 104060 modified in control-structures.foreach by danbrown

From: Date: Fri, 20 May 2011 14:29:30 +0000
Subject: note 104060 modified in control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179911@lists.php.net to get a copy of this message
This function find well the words, add well adds a () around short words, but the array at the end of th function is the same as at the beginning. <?php function isole_mots($chaine) { $chaine = "le petit chat est fou"; $mots = preg_split('/[!,-.;?:()[ ]/', $chaine, -1, PREG_SPLIT_NO_EMPTY); foreach ($mots as $mot) { if (strlen($mot) <= 3) $mot = "(".$mot.")"; print " inside foreach $mot <br>"; } print "after foreach array mots"; print_r($mots); die(); return $mots; } ?> inside foreach (le) inside foreach petit inside foreach chat inside foreach (est) inside foreach (fou) after foreach array motsArray ( [0] => le [1] => petit [2] => chat [3] => est [4] => fou ) --was-- This function find well the words, add well adds a () around short words, but the array at the end of th function is the same as at the beginning. function isole_mots($chaine) { $chaine = "le petit chat est fou"; $mots = preg_split('/[!,-.;?:()[ ]/', $chaine, -1, PREG_SPLIT_NO_EMPTY); foreach ($mots as $mot) { if (strlen($mot) <= 3) $mot = "(".$mot.")"; print " inside foreach $mot <br>"; } print "after foreach array mots"; print_r($mots); die(); return $mots; } inside foreach (le) inside foreach petit inside foreach chat inside foreach (est) inside foreach (fou) after foreach array motsArray ( [0] => le [1] => petit [2] => chat [3] => est [4] => fou ) http://php.net/manual/en/control-structures.foreach.php

« previous php.notes (#179911) next »