<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>php-tips &#8211; Extreme Web Designs</title>
	<atom:link href="https://theextremewebdesigns.com/blog/tag/php-tips/feed/" rel="self" type="application/rss+xml" />
	<link>https://theextremewebdesigns.com/blog</link>
	<description>Web Design and Web Development</description>
	<lastBuildDate>Sun, 16 Jun 2013 19:05:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>
<site xmlns="com-wordpress:feed-additions:1">156673191</site>	<item>
		<title>PHP Refresh Page Examples</title>
		<link>https://theextremewebdesigns.com/blog/php-refresh-page-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/php-refresh-page-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 16 Jun 2013 19:05:28 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-demos]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3899</guid>

					<description><![CDATA[You may know how to refresh page using JavaScript. But, do you know how to refresh page using PHP? In this article, I am going to share very easy way to make page refresh using PHP. So read on for more info. How To Refresh Page Using PHP Let&#8217;s see how to do this by [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>You may know how to refresh page using JavaScript. But, do you know how to refresh page using PHP? In this article, I am going to share very easy way to <em><strong>make page refresh using PHP</strong></em>. So read on for more info.</p>
<p><span id="more-3899"></span></p>
<h2>How To Refresh Page Using PHP</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3899" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s see how to do this by means of an example. The following piece of code will refresh the page after 5 seconds. You may change it as per your needs.</p>
<h3>Example:</h3>
<pre class="lang:xhtml decode:true">echo 'This page will be refreshed after 5 seconds.';
echo '&lt;meta http-equiv="refresh" content="5"&gt;';</pre>
<p>To use the above code, simply copy the second line and change the seconds value from 5 to any value you desire.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3899" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Your Turn!</h5>
<p>Do you know of any other ways to <em><strong>refresh a page using PHP</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-refresh-page-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3899</post-id>	</item>
		<item>
		<title>PHP Return String From String Using Word Limit Examples</title>
		<link>https://theextremewebdesigns.com/blog/php-return-string-from-string-using-word-limit-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/php-return-string-from-string-using-word-limit-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 15 Jun 2013 19:05:42 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-demos]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3892</guid>

					<description><![CDATA[Some times, it might be useful to extract string from a given string, based upon the word count. A good example of this is an excerpt of WordPress. As you know, an &#8220;excerpt&#8221; is just a sneak peak of the article. And it is limited by it&#8217;s word count (or any other desired criteria). So [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Some times, it might be useful to extract string from a given string, based upon the word count. A good example of this is an excerpt of WordPress. As you know, an &#8220;excerpt&#8221; is just a sneak peak of the article. And it is limited by it&#8217;s word count (or any other desired criteria). So how can we achieve the same result in PHP? In this article, I am going to share easy ways to <em><strong>return text from a given text, based upon the word count limit</strong></em>. So follow along for more info.</p>
<p><span id="more-3892"></span></p>
<h2>How To Limit String Using Word Count</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3892" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s see how to do this with an example.</p>
<h3>Example: Consider the following string on which we apply word limit using PHP</h3>
<pre class="lang:xhtml decode:true">This is a custom string. We are now going to apply PHP functions on this and return only the portion of the string based upon the word count.</pre>
<p>Now let&#8217;s limit the above string to a word count of 10 and then return the result. Use the following code to do so:</p>
<pre class="lang:xhtml decode:true">&lt;?php 
function word_limiter($string, $limit) 
{ 
	//break string based upon space
	$str_array = explode(" ", $string); 

	//return the extracted string with our word limit in place
	return implode(" ", array_splice($str_array, 0, $limit)); 
}

$string = 'This is a custom string. We are now going to apply PHP functions on this and return only the portion of the string based upon the word count.';

$word_limit = 10; //Change this based upon your needs

echo word_limiter($string, $word_limit);
?&gt;</pre>
<h3> Output:</h3>
<pre class="lang:xhtml decode:true">This is a custom string. We are now going to</pre>
<p>If you count the number of word in the above Output, you will notice that there are only 10 words. This is exactly what we wanted.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3892" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>That&#8217;s it!</h5>
<p>Do you know of any other ways to <em><strong>limit string using word count in PHP</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-return-string-from-string-using-word-limit-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3892</post-id>	</item>
		<item>
		<title>Easily Get PHP Code From Database &#038; Execute / Parse It</title>
		<link>https://theextremewebdesigns.com/blog/easily-get-php-code-from-database-execute-parse-it/</link>
					<comments>https://theextremewebdesigns.com/blog/easily-get-php-code-from-database-execute-parse-it/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 14 Mar 2013 18:59:14 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3083</guid>

					<description><![CDATA[Do you have some custom PHP code in database that you wish to retrieve and parse / execute and show the output in the browser? Here&#8217;s an easy way to do just that. How to Easily Get PHP Code From Database &#38; Execute / Parse It One way to parse PHP code is to use &#8220;eval&#8221; . So [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Do you have some <em><strong>custom PHP code in database that you wish to retrieve and parse / execute and show the output in the browser</strong></em>? Here&#8217;s an easy way to do just that.</p>
<p><span id="more-3083"></span></p>
<h2>How to Easily Get PHP Code From Database &amp; Execute / Parse It</h2>
<p><em><strong>One way to parse PHP code is to use &#8220;eval&#8221;</strong> </em>. So before we look at how to parse the PHP content from database, let&#8217;s look at the general way to parse PHP code using eval. Consider the following example:</p>
<h3>Example 1: Parse / Execute PHP code in general</h3>
<pre class="lang:php decode:true ">&lt;?php 
$fruit1 = 'Apples';
$fruit2 = 'Grapes';
$my_text = 'I like $fruit1 and $fruit2';
echo $my_text . "&lt;br&gt;"; 
eval("\$my_text = \"$my_text\";"); 
echo $my_text . "&lt;br&gt;"; 
?&gt;</pre>
<p>When you execute the above code, you will see the following output:</p>
<pre class="lang:php decode:true">I like $fruit1 and $fruit2
I like Apples and Grapes</pre>
<p>So simply remove the first echo if you want to use it to parse general PHP code. Now let&#8217;s see how to use eval on PHP content from database.</p>
<h3>Example 2: Get PHP code from database and Parse / Execute it</h3>
<p>Let&#8217;s say that you have some custom PHP code in database that you wish to run and show the output of. So consider the following code as stored in database:</p>
<pre class="lang:php decode:true" title="PHP code in database">&lt;form method="post" class="my_form_class" id="my_form" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" &gt;

&lt;/form&gt;</pre>
<p>Note the action attribute of the form. If you get this code from database and try to run it, you will see an error that breaks the code because the code from database contains the PHP start and closing tags. So to avoid that, you will need to modify our code a bit to make it work without breaking. So here&#8217;s how it can be done:</p>
<pre class="lang:php decode:true crayon-selected" title="Apply eval on content from database to execute the PHP code without breaking it">$final_content = eval('?&gt;' . $database_content_with_php_code . '&lt;?php ');

echo $final_content;</pre>
<p>Follow the above steps and you will see that the content can now be shown properly in browser.</p>
<h4>NOTE:</h4>
<p>Using &#8220;eval&#8221; is considered dangerous to use and not it is not recommended because of the vulnerabilities associated with it. Read more about eval <a title="Read more about why not to use eval" href="http://php.net/manual/en/function.eval.php" target="_blank">here</a>.</p>
<h4>Your Turn!</h4>
<p>Do you know of any other ways to <em><strong>get PHP code from database and parse / execute it</strong></em>? Please feel free to share your thoughts by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/easily-get-php-code-from-database-execute-parse-it/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3083</post-id>	</item>
		<item>
		<title>PHP Replace Array Value Example</title>
		<link>https://theextremewebdesigns.com/blog/php-replace-array-value-how-to-replace-array-value-using-php-example/</link>
					<comments>https://theextremewebdesigns.com/blog/php-replace-array-value-how-to-replace-array-value-using-php-example/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 08 Feb 2013 22:03:20 +0000</pubDate>
				<category><![CDATA[Demos]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Demos]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[demos-php]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=2270</guid>

					<description><![CDATA[One of the coolest things of array is that you can hold as much data as you need. So when dealing with arrays, there might have been a time when one would come across a requirement to replace or change array value with another value. In this article, I am going to show you how [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>One of the coolest things of <a title="PHP Add To An Array | Add Element To Array Using PHP Examples" href="https://theextremewebdesigns.com/blog/php-add-to-an-array-add-element-to-array-using-php-examples/" target="_blank">array</a> is that you can hold as much data as you need. So when dealing with arrays, there might have been a time when one would come across a requirement to <strong>replace or change array value with another value</strong>. In this article, I am going to show you <em><strong>how to use PHP to replace array valu</strong></em> by means of simple examples. Demos follow.<span id="more-2270"></span></p>
<h2>How To use PHP to Replace Array Value</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2270" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s consider a simple example. Let&#8217;s assume that we have an array that consists of fruit names. We will now choose a fruit name (value) and we will replace this value in this array with another value i.e. with another fruit name. In this scenario, there arises 2 cases.</p>
<p>1. Replacing the array value assuming that all values in the array are unique.</p>
<p>2. Replacing the array value assuming that some or all values in the array may be duplicate values of an original value.</p>
<p>So let&#8217;s start with the first case.</p>
<h3>Example 1: Replacing the Array Value Using PHP assuming that all values in the array are unique</h3>
<pre class="lang:php decode:true" title="Example 1">echo 'Example 1 - Replace value "apple" with value "strawberry"&lt;br /&gt;';

//Declare an array
$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple', 'apple', 'guava', 'apple');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

//Replace the value "apple" with "strawberry" in the array
$search_for = "apple";
$replace_with = "strawberry";
for($i=0;$i&lt;count($my_fruits_array);$i++) 
{
	if($my_fruits_array[$i] == $search_for) 
	{
		$my_fruits_array[$i] = $replace_with;
	}
}

//Print the contents of the array.
echo 'Following are the array contents AFTER removing the duplicate values from array:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';</pre>
<h3>Example 2: Replacing the Array Value Using PHP assuming that all mutiple values in the array need replacement</h3>
<pre class="lang:php decode:true crayon-selected" title="Example 2: Replace Array Value Using PHP assuming that all mutiple values in the array need replacement">echo 'Example 2: Replace the value "apple" with value "strawberry" and "mango" value with "fig" value in array &lt;br /&gt;';

//Declare an array
$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple', 'apple', 'guava', 'apple', 'mango');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

//Replace the value "apple" with "strawberry" value and "mango" value with "fig" value in array
$replacements_array = array( 'apple' =&gt; 'strawberry', 'mango' =&gt; 'fig');

//For each of the replacement values in the array, loop through the array values
foreach ( $replacements_array as $key1 =&gt; $val1 )
{
	//Loop through each of the original $my_fruits_array so that we can check if the value matches with our replacement array key.If yes, we will replace the value of $my_fruits_array with the corresponding replacement value from $replacements_array array.
	foreach ( $my_fruits_array as $key2 =&gt; $val2 )
	{	
		//If the value to be reaplaced in replacements_array == already existing value in $my_fruits_array
		if( $key1 == $val2 )
		{
			//Then simply use the index of $my_fruits_array[ to update its value with the replacement value from $replacements_array
			$my_fruits_array[$key2] = $val1;
		}
	}
}

//Print the contents of the array.
echo 'Following are the array contents AFTER removing the duplicate values from array:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2270" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>That&#8217;s it!</h5>
<p>Do you know of any other ways to use  <em><strong>PHP to replace array values</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-replace-array-value-how-to-replace-array-value-using-php-example/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2270</post-id>	</item>
		<item>
		<title>PHP Delete Item From Array Examples</title>
		<link>https://theextremewebdesigns.com/blog/php-delete-item-from-array-how-to-delete-item-from-array-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/php-delete-item-from-array-how-to-delete-item-from-array-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 08 Feb 2013 12:40:04 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=2251</guid>

					<description><![CDATA[Arrays, as always, have been a very important concept. While working with arrays, there might have been an instance where you wanted to delete an array element. In this article, I am going to share with you easy ways to use PHP to delete item from array by means of easy examples. How To Delete Item [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong></strong><a title="PHP Add To An Array | Add Element To Array Using PHP Examples" href="https://theextremewebdesigns.com/blog/php-add-to-an-array-add-element-to-array-using-php-examples/" target="_blank">Arrays</a>, as always, have been a very important concept. While working with arrays, there might have been an instance where you wanted to <strong>delete an array element</strong>. In this article, I am going to share with you easy ways to use <em><strong>PHP to delete item from array</strong></em> by means of easy examples.</p>
<p><span id="more-2251"></span></p>
<h2>How To Delete Item From Array</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2251" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s  assume that we have an array of states. So we will see few examples that satisfy the following requirements:</p>
<p>1. Deleting an Array Element when array consists of unique values.</p>
<p>2. Deleting an Array Element when array consists of duplicate values &amp; retain the original value.</p>
<p>3. Deleting an Array Element when array consists of duplicate values &amp; delete the original value as well.</p>
<p>4. Deleting an Array Element when array consists of multiple repeated values using PHP. The original value will be retained, and only the duplicates will be removed.</p>
<p>5. Deleting an Array Element when array consists of multiple repeated values using PHP Remove all duplicated values. The original value will be deleted along with the duplicates and the result will be an array with only unique values.</p>
<p>So let&#8217;s get stated with our first case:</p>
<h3>Example 1: Remove Element From Array when array consists of unique values using PHP</h3>
<p><strong>When to use:</strong> Use only when you know a specific item / value and you are sure that it is unique and non-repeated in an array and you want to remove just that specific value.</p>
<pre class="lang:php decode:true" title="Example 1">//Example 1

//Declare an array
$my_states_array = array('Texas', 'Alabama', 'New York', 'Alaska');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';

//Remove "Texas" value from array
if( ( $key = array_search('Texas', $my_states_array) ) !== false ) 
{
    unset($my_states_array[$key]);
}

//Print the contents of the array.
echo 'Following are the array contents AFTER removing the value from array:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';</pre>
<h3>Example 2: Remove Element From Array when array consists of duplicate values using PHP and retain only the original value</h3>
<p><strong>When to use:</strong> Use when you know a specific value and you think there might be repeated values of this value and you would want to retain only the original value and delete the rest of the duplicate values.</p>
<pre class="lang:php decode:true" title="Example 2">//Example 2

$my_states_array = array('Texas', 'Alabama', 'New York', 'Alaska', 'Texas', 'Utah');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';

//Remove "Texas" value from array, only the ones that are duplicated &amp; retain the original value
$my_states_array = array_unique($my_states_array);

//Print the contents of the array. 
echo 'Following are the array contents AFTER removing the value from array, retaining the original Texas value:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';</pre>
<h3>Example 3: Remove Element From Array when array consists of unique values using PHP and delete the original value as well</h3>
<p><strong>When to use: </strong>Use when you want to delete a specific value or item from an array when you think this array might have repeated values for this item. So this way, the duplicated values will be deleted along with original value.</p>
<pre class="lang:php decode:true" title=" Example 3">//Example 3

$my_states_array = array('Texas', 'Alabama', 'New York', 'Alaska', 'Texas', 'Utah');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';

//Remove All "Texas" value from array including original value
$my_states_array = array_diff($my_states_array, array('Texas'));

//Print the contents of the array. 
echo 'Following are the array contents AFTER removing the value from array, removing even the original Texas value:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';</pre>
<h3>Example 4: Remove Element From Array when array consists of multiple repeated values using PHP and RETAIN the original value</h3>
<p><strong>When to use:</strong> Use when you have a dynamic array that has multiple repeated values and you don&#8217;t know what these values might be. So if you are not worried about what these values are and don&#8217;t care about them, but you want to retain only unique values plus only one of the duplicated items in the array and delete the duplicated items, then go ahead &amp; use this.</p>
<pre class="lang:php decode:true" title="Example 4">//Example 4

$my_states_array = array('Texas', 'Alabama', 'New York', 'Alaska', 'Texas', 'Utah',  'Alaska', 'New York');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';

//Remove All multiple duplicate values and retain original value
$my_states_array = array_unique($my_states_array);

//Print the contents of the array. 
echo 'Following are the array contents AFTER removing the value from array, removing even the original value:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';</pre>
<h3>Example 5: Remove Element From Array when array consists of multiple repeated values using PHP and DELETE the original value</h3>
<p><strong>When to use:</strong> Use when you have a dynamic array that has multiple repeated values  and you don&#8217;t know what these values might be. So if you are not worried about what these values are and don&#8217;t care about them, but you want to retain purely only unique values in the array and delete all the duplicated items, then go ahead &amp; use this. So if an array item is repeated at least once, then it will be removed from the result, thereby giving you only pure, non-repeating values.</p>
<pre class="lang:php decode:true" title="Example 5">//Example 5

$my_states_array = array('Texas', 'Alabama', 'New York', 'Alaska', 'Texas', 'Utah',  'Alaska', 'New York');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_states_array);
echo '&lt;/pre&gt;';

//First get all unique values of array
$unique_array = array_unique($my_states_array);

echo 'Following are the array contents AFTER applying array_unique function. We get only the unique values and this will leave out multiple, repeated values&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($unique_array);
echo '&lt;/pre&gt;';

//Compute the difference of the original array and the unique array and return an array containing all the values from $my_states_array that are not present in the other arrays ($unique_array). So this means that only the unique, non-repeated values will be left out and the resultant array will contain values that were repeated at least once.
$compared_array = array_diff_assoc($my_states_array, $unique_array);

//Print the contents of the compared_array. 
echo 'Following are the array contents AFTER applying array_diff_assoc. This will leave the most unique, non-repeated values and will return an array of values that were repeated at least once:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($compared_array);
echo '&lt;/pre&gt;';

//Apply array_diff to compute difference of two arrays and return the difference i.e  it returns an array containing all the entries from my_states_array that are not present in any of the other arrays i.e. $compared_array.
$all_unique_non_repeated_values = array_diff($my_states_array, $compared_array);

echo 'Following are the array contents AFTER applying array_diff. This will leave the most unique, non-repeated values and will return an array of values that were repeated at least once. So the following is our FINAL DESIRED RESULT:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($all_unique_non_repeated_values);
echo '&lt;/pre&gt;';
echo '&lt;br /&gt;/*=============================================================================*/&lt;br /&gt;';</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2251" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p><strong>That&#8217;s it!<br />
</strong>Do you know of any other ways to use <strong><em>PHP to delete item from array</em>?</strong> Feel free to share by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-delete-item-from-array-how-to-delete-item-from-array-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2251</post-id>	</item>
		<item>
		<title>Using PHP To Find Value In Array</title>
		<link>https://theextremewebdesigns.com/blog/php-find-value-in-array-how-to-find-value-in-array-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/php-find-value-in-array-how-to-find-value-in-array-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 08 Feb 2013 08:15:18 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=2246</guid>

					<description><![CDATA[Arrays are very important concept, be it any programming language. So while working with arrays, there might be a necessity to find a specific value in an array. In this article, I am going to share a very simple yet easy way to use  PHP to find value in array by means of examples. How to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Arrays are very important concept, be it any programming language. So while <a title="PHP Add To An Array | Add Element To Array Using PHP Examples" href="https://theextremewebdesigns.com/blog/php-add-to-an-array-add-element-to-array-using-php-examples/" target="_blank">working with arrays</a>, there might be a necessity to find a specific value in an array. In this article, I am going to share a very simple yet easy way to use  <em><strong>PHP to find value in array</strong></em> by means of examples.</p>
<h2>How to use PHP to Find Value In Array</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2246" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s assume that we have an array that contains fruits names. Now we would like to find if the value i.e. a specific fruit name exists in our array of fruits. PHP provides us with a very simple function called <strong>&#8220;array_search&#8221;</strong>. So <strong>&#8220;array_search&#8221;</strong>  searches an array for a given value and returns the corresponding key if they value is successfully found. All of the code is highly commented, so make sure you read each line to understand what each step actually does.</p>
<h3>Example 1: By using array_search when array consists of Unique Values</h3>
<pre class="lang:php decode:true" title="Example 1">&lt;?php 
//Example 1: Declare an array with unique values===============================================/
$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple');

//Print the contents of the array. Use the &lt;pre&gt; tags to output the array in readable format.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

$key = array_search('grapes', $my_fruits_array);

//Echo the Key of the found value
echo 'The key of the grapes value is: '.$key;

echo '&lt;br /&gt;&lt;br /&gt;';
?&gt;</pre>
<h3>Example 2: By using array_search when array consists of Repeated/Duplicate Values</h3>
<pre class="lang:php decode:true" title="Example 2">&lt;?php 
//Example 2: Declare an array with duplicate values. We will find index/key of repeated values===/
$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple', 'grapes');

//Print the contents of the array. Use the &lt;pre&gt; tags to output the array in readable format.
echo 'Following are the array contents with duplicated values:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

//Iterate through all values of our array
foreach( $my_fruits_array as $key =&gt; $val )
{
	//If our desireds value is found, then simply store its key in a different array
	if( 'grapes' == $val )
	{
		$all_indices_for_value[] =  $key;
	}
}

echo 'Print all indicies of the values found in array:&lt;br /&gt;';
//Print all indicies of the values found in array
echo '&lt;pre&gt;';
print_r($all_indices_for_value);
echo '&lt;/pre&gt;';

echo '&lt;br /&gt;&lt;br /&gt;';
?&gt;</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2246" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p><strong>That&#8217;s it!</strong><br />
Do you know of any other ways to use  <em><strong>PHP to find value in array</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-find-value-in-array-how-to-find-value-in-array-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2246</post-id>	</item>
		<item>
		<title>How To Delete File Or Remove File Using PHP Examples</title>
		<link>https://theextremewebdesigns.com/blog/php-delete-file-or-remove-file/</link>
					<comments>https://theextremewebdesigns.com/blog/php-delete-file-or-remove-file/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 08 Feb 2013 06:57:42 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-demos]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=2240</guid>

					<description><![CDATA[When working with files in PHP, there may be a necessity to create files dynamically and at the same time, remove file or delete file using PHP.  In this article, I am going to share a very easy way to delete a file using PHP. The actual code is just 1 line, so it&#8217;s super easy to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>When working with files in PHP, there may be a necessity to create files dynamically and at the same time, <em><strong>remove file or delete file using PHP</strong></em>.  In this article, I am going to share a very easy way to delete a file using PHP. The actual code is just 1 line, so it&#8217;s super easy to follow.<span id="more-2240"></span></p>
<h2>Examples On How To Remove File Or Delete File Using PHP</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2240" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>To do this, we simply use the &#8220;unlink&#8221; function. So what unlink simply does is it <strong>&#8220;Deletes a file&#8221;</strong>. That&#8217;s it! Nothing more!</p>
<p><strong>Command:</strong></p>
<pre class="lang:php decode:true" title="Example">unlink( $filename );</pre>
<h3>Example: Using PHP to delete a file with the help of unlink function</h3>
<p>In this example, I am going to first create a sample test file and then once it is created in the following steps, I will delete the file using PHP.</p>
<pre class="lang:php decode:true" title="Example">&lt;?php
$temp_file_name = tempnam ('tmp/', "Test"); 

if( $temp_file_name )
{
	echo 'File successfully CREATED.&lt;br /&gt;';	
}
else
{
	echo 'Unable to CREATE file.&lt;br /&gt;';		
}

$fp = fopen($temp_file_name, "w"); 
fwrite($fp, 'Some sample content'); 
fclose($fp); 				

$delete_result = unlink($temp_file_name); 

if( $delete_result )
{
	echo 'File successfully DELETED.&lt;br /&gt;';	
}
else
{
	echo 'Unable to DELETE the file.&lt;br /&gt;';		
}
?&gt;</pre>
<p>If you have tried the demo, you will notice that first, the file is created &amp; in the succeeding step, the file is deleted. If you have not yet tried the demo, then do it by clicking the button below.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2240" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p><strong>Your Turn!</strong><br />
Do you know of any other ways of using <em><strong>PHP to delete file or remove a file</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-delete-file-or-remove-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2240</post-id>	</item>
		<item>
		<title>How To Remove Last Character From String Using PHP &#8211; Examples</title>
		<link>https://theextremewebdesigns.com/blog/php-remove-last-character-how-to-remove-last-character-from-string-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/php-remove-last-character-how-to-remove-last-character-from-string-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 08 Feb 2013 05:39:29 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=2230</guid>

					<description><![CDATA[Some times while dealing with strings in PHP, it may be required to remove the last character of a string. In this article, I am going to share very easy ways of removing last character from string using PHP by means of multiple examples. How To Remove Last Character Using From String Using PHP Examples [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Some times while dealing with strings in PHP, it may be required to remove the last character of a string. In this article, I am going to share very easy ways of <em><strong>removing last character from string using PHP</strong></em> by means of multiple examples.<span id="more-2230"></span></p>
<h2>How To Remove Last Character Using From String Using PHP Examples</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2230" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let us assume that we have a string with some random text. So lets look at the different available ways to remove the last character from string. Consider our sample string below:</p>
<pre class="lang:php decode:true" title="Sample String">&lt;?php

$my_string = 'Hello! This is my random string';

?&gt;</pre>
<h3>Example 1: By using rtrim</h3>
<p>rtrim — Strips whitespace (or other characters) from the end of a string <strong>Command:</strong></p>
<pre class="lang:php decode:true">rtrim($string,'x');</pre>
<p><strong>Usage:</strong></p>
<pre class="lang:php decode:true" title="Using rtrim">/*Example1:=====================================================================*/
echo 'Example 1: Removing the Last character from string using PHP&lt;br /&gt;';
echo "Before using rtrim: &lt;br /&gt;";

//Sample String
$my_string = 'Hello! This is my random string';

//Echo the sample string
echo $my_string . '&lt;br /&gt;&lt;br /&gt;';

//Apply rtrim function to delete the last character from string
echo "After using rtrim: &lt;br /&gt;";

echo rtrim($my_string, 'g');

echo '&lt;br /&gt;&lt;br /&gt;';</pre>
<h3>Example 2: By using substr_replace</h3>
<p>substr_replace — Replace text within a portion of a string <strong>Command:</strong></p>
<pre class="lang:php decode:true" title="Using substr_replace">substr_replace($string ,"",-1);</pre>
<p><strong>Usage:</strong></p>
<pre class="lang:php decode:true" title="Example 2">/*Example2:=====================================================================*/
echo 'Example 2: Removing the Last character from string using PHP&lt;br /&gt;';
echo "Before using substr_replace: &lt;br /&gt;";

//Sample String
$my_string = 'Hello! This is my random string';

//Echo the sample string
echo $my_string . '&lt;br /&gt;&lt;br /&gt;';

//Apply rtrim function to delete the last character from string
echo "After using substr_replace: &lt;br /&gt;";

echo substr_replace($my_string ,"",-1);

echo '&lt;br /&gt;&lt;br /&gt;';</pre>
<h3>Example 3: By using substr</h3>
<p>substr — Returns part of a string <strong>Command:</strong></p>
<pre class="lang:php decode:true" title="Using substr">substr($string, 0, -1);</pre>
<p><strong>Usage:</strong></p>
<pre class="lang:php decode:true" title="Example 3">/*Example3:=====================================================================*/
echo 'Example 3: Removing the Last character from string using PHP&lt;br /&gt;';
echo "Before using substr: &lt;br /&gt;";

//Sample String
$my_string = 'Hello! This is my random string';

//Echo the sample string
echo $my_string . '&lt;br /&gt;&lt;br /&gt;';

//Apply rtrim function to delete the last character from string
echo "After using substr: &lt;br /&gt;";

echo substr($my_string, 0, -1);

echo '&lt;br /&gt;&lt;br /&gt;';</pre>
<h3>Example 4: By Using mb_substr</h3>
<p><strong>Command:</strong></p>
<pre class="lang:php decode:true" title="Using mb_substr">mb_substr — Get part of string</pre>
<p><strong>Usage:</strong></p>
<pre class="lang:php decode:true crayon-selected" title="Example 4">/*Example4:=====================================================================*/
echo 'Example 4: Removing the Last character from string using PHP&lt;br /&gt;';
echo "Before using mb_substr: &lt;br /&gt;";

//Sample String
$my_string = 'Hello! This is my random string';

//Echo the sample string
echo $my_string . '&lt;br /&gt;&lt;br /&gt;';

//Apply mb_substr function to delete the last character from string
echo "After using mb_substr: &lt;br /&gt;";

echo mb_substr($my_string, 0, -1);

echo '&lt;br /&gt;&lt;br /&gt;';</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2230" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p><strong>Your Turn!</strong></p>
<p>Do you know of any other ways to use <strong><em>PHP to remove last character from string</em>?</strong> Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-remove-last-character-how-to-remove-last-character-from-string-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2230</post-id>	</item>
		<item>
		<title>How To Remove Duplicates From Array Using PHP</title>
		<link>https://theextremewebdesigns.com/blog/php-remove-duplicates-from-array-remove-duplicate-values-from-array-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/php-remove-duplicates-from-array-remove-duplicate-values-from-array-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 07 Feb 2013 06:12:22 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-demos]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=2221</guid>

					<description><![CDATA[While working with arrays, there may have been a time when you came across duplicate values in array. In some cases, these duplicates values are undesirable and you may want to remove these duplicate values from the same array. So do you know how to remove duplicate values from array? If not then here are [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>While <a title="PHP Add To An Array | Add Element To Array Using PHP Examples" href="https://theextremewebdesigns.com/blog/php-add-to-an-array-add-element-to-array-using-php-examples/" target="_blank">working with arrays</a>, there may have been a time when you came across duplicate values in array. In some cases, these duplicates values are undesirable and you may want to remove these duplicate values from the same array. So do you know how to remove duplicate values from array? If not then here are easy examples that show you how to  use <em><strong>PHP to remove duplicates from array</strong></em>. <span id="more-2221"></span></p>
<h2>Using PHP to Remove Duplicate Values From Array</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2221" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s consider that we have an array that contains fruits names. One of the fruits is now duplicated in the array and we would like to remove this duplicated value. Consider the following array below:</p>
<pre class="lang:php decode:true" title="Sample array with duplicate values">$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple', 'apple', 'guava', 'apple');</pre>
<p>As you can see in the above array, the fruit &#8220;apple&#8221; appears thrice i.e. it is duplicated twice. So now  we would like to retain only the first occurrence of &#8220;apple&#8221; and remove the other two duplicate values from the array.</p>
<h3>Example 1 &#8211; Remove duplicates from array using PHP</h3>
<pre class="lang:php decode:true" title="Example 1">&lt;?php 

echo 'Example 1: Removing a value from the array - Remove value "apple" &lt;br /&gt;';

//Declare an array
$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple', 'apple', 'guava', 'apple');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

//Remove duplicated "apple" value from array
$my_fruits_array_new = array_unique($my_fruits_array);

//Print the contents of the array.
echo 'Following are the array contents AFTER removing the duplicate values from array:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array_new);
echo '&lt;/pre&gt;';
?&gt;</pre>
<h3>Example 2 &#8211; Delete Duplicates From Array Using PHP</h3>
<pre class="lang:php decode:true" title="Example 2">&lt;?php

echo '&lt;br /&gt;Example 2: Removing a value from the array - Remove value "grapes" &lt;br /&gt;';

$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple', 'apple', 'guava', 'apple');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

//Remove "apple" value from array
$my_fruits_array_new = array_map('unserialize', array_unique(array_map('serialize', $my_fruits_array)));

//Print the contents of the array. 
echo 'Following are the array contents AFTER removing the value from array:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array_new);
echo '&lt;/pre&gt;';

?&gt;</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2221" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h4>That&#8217;s it!</h4>
<p>Do you know of any other ways to use <em><strong>PHP to </strong><strong>delete duplicate values from array? </strong></em>Feel free to share by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-remove-duplicates-from-array-remove-duplicate-values-from-array-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2221</post-id>	</item>
		<item>
		<title>PHP Remove Value From Array Examples</title>
		<link>https://theextremewebdesigns.com/blog/php-remove-value-from-array-how-to-remove-value-from-array-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/php-remove-value-from-array-how-to-remove-value-from-array-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 07 Feb 2013 05:44:34 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=2211</guid>

					<description><![CDATA[While dealing with arrays in PHP, there could be times when you would want to remove a specifc value from array, once you know what that value is. This could help you retain only the data that you want in the array. So do you know how to use PHP to remove value from array? [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>While dealing with <a title="PHP Add To An Array | Add Element To Array Using PHP Examples" href="https://theextremewebdesigns.com/blog/php-add-to-an-array-add-element-to-array-using-php-examples/" target="_blank">arrays in PHP</a>, there could be times when you would want to remove a specifc value from array, once you know what that value is. This could help you retain only the data that you want in the array. So do you know how to use <em><strong>PHP to remove value from array</strong></em>? If not, this article is for you. In this article, I am going to share very easy ways to to remove single value or remove multiple values from array using PHP by means of examples.</p>
<h2><span id="more-2211"></span>How To Remove Value From Array Using PHP</h2>
<p>Let&#8217;s assume that we have an array. For the sake of the example, let&#8217;s assume that we have an array of fruit names. Now we will see how easily we can delete an array value, provided we know the value that we wish to remove.  Let&#8217;s assume that in the fruits array, we want to remove the array value &#8220;grapes&#8221;.</p>
<h3>Example 1 &#8211; Remove specific value from array by using its value</h3>
<pre class="lang:xhtml decode:true" title="Example 1">&lt;?php 

echo 'Example 1: Removing a value from the array&lt;br /&gt;';

//Declare an array
$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

//Remove "grapes" value from array
if( ( $key = array_search('grapes', $my_fruits_array) ) !== false ) 
{
    unset($my_fruits_array[$key]);
}

//Print the contents of the array.
echo 'Following are the array contents AFTER removing the value from array:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

?&gt;</pre>
<h3>Example 2 &#8211; Remove specific value from array using its value</h3>
<pre class="lang:xhtml decode:true" title="Example 2">&lt;?php 

echo 'Example 2: Removing a value from the array&lt;br /&gt;';

$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple');

//Print the contents of the array.
echo 'Following are the original array contents:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

//Remove "grapes" value from array
$my_fruits_array = array_diff($my_fruits_array, array('grapes'));

//Print the contents of the array. 
echo 'Following are the array contents AFTER removing the value from array:&lt;br /&gt;';
echo '&lt;pre&gt;';
print_r($my_fruits_array);
echo '&lt;/pre&gt;';

?&gt;</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=2211" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p><strong>That&#8217;s it!</strong></p>
<p>Do you know of any other ways to use <strong><em>PHP to  remove value from array</em></strong>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-remove-value-from-array-how-to-remove-value-from-array-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2211</post-id>	</item>
	</channel>
</rss>
