Display Array Value in Textbox in PHP

In this article, we going to see how to achieve Display Array Value in Textbox in PHP and keep only the values that appear in the textbox. For that, we will be going to use PHP string and array function with the help of this we will get an array value for that we going to use this PHP string function to convert this into the string.

Going to see Display Array Value in Textbox in PHP step by step in a simple way.

Before discussion regarding this, first we will check which PHP string function going to use.As there many string define and used for many thing to achieve any task in programming.But we going to use only single string function to achieve this.

The PHP string and array we use are as follow as:

  • implode()
  • array_search()

To achieve Display Array Value in Textbox in PHP. We First going to declare the Form in HTML tag.
Within form tag, we going to declare the three input tag with attribute type, name, and one input tag is with attribute type “submit”.

By clicking on the input type submit button the value of both the input tag of form post the value.

We will collect all the post value, after collecting all the post value, we will search for the input tag value for input tag type submit for that we will be going to use the array search function to search ADD so that we can unset this from all array value.

After unset this, we have then only two input tag value in an array. Then this array value we going to use PHP string function to convert into a string.

Then finally we add this converted string value into an input tag called type textbox.

Below is the full example how we done pro-grammatically.

$arrval = array();

$arrval= $_POST;
if (($key = array_search('ADD', $arrval)) !== false) {
$fnarry  = implode(",",$arrval);	 
echo "Output is :<input type='text' value='$fnarry'/><br/><br/>";			
<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>contains demo</title>
<form method="post">
Enter num1 <input type="text" name="fnum"/><hr/>
Enter num2 <input type="text" name="snum"/><hr/>	   		   
<input type="submit"  name="add" value="ADD"/>

When we going to run this code in browser then you get output are as follow as:

Out put value

Now we will discuss regarding PHP string and array function. As there are many string and array function in php.But we going to check only above string and array function.

What is PHP implode() Function ?

PHP implode() Function Join array elements with a string.

Syntax is implode(separator,array).Important point in this is implode() function returns a string from the elements of an array.

$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);

OUTPUT : Hello World! Beautiful Day!

What is PHP array_search() Function ?

PHP array_search() function search an array for a value and returns the key.

Syntax is array_search(value, array, strict).Important point in this is function search the values in arrays, and return the key.

I hope you liked my this article. If you have any queries or any question regarding this, Feel free to comment on Me.

Leave a Comment