Can’t get array value in a for loop when it runs the second time in PHP

This code did not work for me in a PHP application-

<?php

$text = $_POST["text"];
$text = explode("||", $text);
for($j=0;$j<2;$j++)
	{
		echo $text[$j];
    }

?>

This worked-

<?php

for($j=0;$j<2;$j++)
	{
		$text = $_POST["text"];
		$text = explode("||", $text);
		echo $text[$j];
    }

?>

NOTE*- May work here but in case above syntax does not work then use this syntax.

Leave a Comment