KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Stringify arrays using php implode
PRODUCT: 4D | VERSION: 14.1 | PLATFORM: Mac & Win
Published On: September 3, 2014

PHP command “implode” can be used to join elements of an array into a string.

$arr{1}:=1
$arr{2}:=2
$arr{3}:=3

$err:=PHP Execute("";"implode";$result;",";->$arr)
//$result=”1,2,3”


Below is a method that will take in an array, and return the elements concatenated together in a string.
// Method: Stringify_Array
// Parameters
// $1 - pointer to the array
// $2 - split character
// Return
// $0 - string of elemets in the array separated by the split character
// ----------------------------------------------------------------------


C_POINTER($1;$arr)
C_TEXT($0;$2;$split;$result)
C_BOOLEAN($err)
If (Count parameters>0)
  $arr:=$1
  If(Count parameters>=2)
    $split:=$2
  Else
    $split:=""
  End if
  $err:=PHP Execute("";"implode";$result;$split;$arr)
  $0:=$result
End if