Jump to content


Photo

Encapsulating code


  • Please log in to reply
1 reply to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 16 October 2006 - 07:40 PM

Hi everyone

sorry to post again, but im having a problem figuring something out, basically I have a whole load of php code which I want to capture and then print somewhere else on the page.

My code I use is

$idnum = $rows['id'];
print $idnum;
if ($num > 1) 
{
print " AND ";
}
print " ";
}

Basically I want to take the above and somehow encapsulate it so that I can print it on the page.

When the above code is printed, it looks like

'23' AND '45' AND '65' AND ''

So I want to be able to produce

'23' AND '45' AND '65' AND ''

somewhere else on the page, I guess I need to encapsulate using something like

$encapsulatedcode = "<CODE IN HERE>";

But that doesnt seem to work for me

Any help would be great

Regards

Dave

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 16 October 2006 - 07:48 PM

if I get this correctly, you should be able to use implode to get what you want.

Example:
<?php
$array = array(25, 45, 35, 55);
$encapsulate = implode(" AND ", $array);

echo $encapsulate;
?>

will output
25 AND 45 AND 35 AND 55

Ray





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users