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

Date Published: 05/02/2021 Published By: JaiSchool

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.

Publish A Comment

Leave a Reply

Your email address will not be published. Required fields are marked *