<?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>Array Function Archives - The Code Developer</title>
	<atom:link href="https://www.thecodedeveloper.com/tag/array-function/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.thecodedeveloper.com/tag/array-function/</link>
	<description>The Code Developer is a Programming Blog.</description>
	<lastBuildDate>Sun, 02 Dec 2018 16:04:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>How to merge two or more arrays into one array in PHP ?</title>
		<link>https://www.thecodedeveloper.com/merge-two-or-more-arrays-into-one-array/</link>
					<comments>https://www.thecodedeveloper.com/merge-two-or-more-arrays-into-one-array/#respond</comments>
		
		<dc:creator><![CDATA[Vikas Kumar]]></dc:creator>
		<pubDate>Sun, 02 Dec 2018 15:16:35 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array Function]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=3618</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="1020" height="620" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="merge two or more arrays into one array" decoding="async" fetchpriority="high" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array.png 1020w, https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array-442x269.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array-768x467.png 768w" sizes="(max-width: 1020px) 100vw, 1020px" /></div>
<p>In this article you will learn how to merge two or more arrays into one array in PHP. You can easily do it after use array_merge() function to merge the elements or values of two or more arrays together into a single array. array_merge() function The array_merge() function merges one or more arrays into one [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/merge-two-or-more-arrays-into-one-array/">How to merge two or more arrays into one array in PHP ?</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="1020" height="620" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="merge two or more arrays into one array" decoding="async" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array.png 1020w, https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array-442x269.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/12/merge-two-or-more-arrays-into-one-array-768x467.png 768w" sizes="(max-width: 1020px) 100vw, 1020px" /></div><p>In this article you will learn how to <strong>merge two or more arrays into one array</strong> in PHP. You can easily do it after use <strong>array_merge()</strong> function to merge the elements or values of two or more arrays together into a single array.</p>
<h4 class="sitemaincolor">array_merge() function</h4>
<p>The <strong>array_merge()</strong> function merges one or more arrays into one array. <b>Note:</b> If two or more array elements have the same key, the last one overrides the others.</p>
<h2>Merge two or more arrays into one array in PHP</h2>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$array1 = array(&quot;yellow&quot;, &quot;red&quot;, &quot;green&quot;, &quot;orange&quot;, &quot;purple&quot;);
$array2 = array(&quot;pink&quot;, &quot;brown&quot;, &quot;green&quot;, &quot;orange&quot;, &quot;red&quot;);
$array  = array_merge($array1, $array2);
print_r($array);
?&gt;
</pre>
<h5>The above example will output:</h5>
<pre class="brush: php; title: ; notranslate">
Array
(
    &#x5B;0] =&gt; yellow
    &#x5B;1] =&gt; red
    &#x5B;2] =&gt; green
    &#x5B;3] =&gt; orange
    &#x5B;4] =&gt; purple
    &#x5B;5] =&gt; pink
    &#x5B;6] =&gt; brown
    &#x5B;7] =&gt; green
    &#x5B;8] =&gt; orange
    &#x5B;9] =&gt; red
)
</pre>
<p>The post <a href="https://www.thecodedeveloper.com/merge-two-or-more-arrays-into-one-array/">How to merge two or more arrays into one array in PHP ?</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/merge-two-or-more-arrays-into-one-array/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to merge two arrays without duplicate values in PHP?</title>
		<link>https://www.thecodedeveloper.com/merge-two-arrays-without-duplicate-values-in-php/</link>
					<comments>https://www.thecodedeveloper.com/merge-two-arrays-without-duplicate-values-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Vikas Kumar]]></dc:creator>
		<pubDate>Fri, 30 Nov 2018 17:22:50 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array Function]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=3333</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="1020" height="620" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="How to merge two arrays without duplicate values in PHP?" decoding="async" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values.png 1020w, https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values-442x269.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values-768x467.png 768w" sizes="(max-width: 1020px) 100vw, 1020px" /></div>
<p>In this tutorial, we will explain you how to merge two arrays without duplicate values in PHP. You can use the PHP array_unique() function and PHP array_merge() function together to merge two arrays into one array without duplicate values in PHP. Merge two arrays You can use PHP array_merge function for merging both arrays into [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/merge-two-arrays-without-duplicate-values-in-php/">How to merge two arrays without duplicate values in PHP?</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="1020" height="620" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="How to merge two arrays without duplicate values in PHP?" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values.png 1020w, https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values-442x269.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/11/merge-two-arrays-without-duplicate-values-768x467.png 768w" sizes="auto, (max-width: 1020px) 100vw, 1020px" /></div><p>In this tutorial, we will explain you <strong>how to merge two arrays without duplicate values in PHP</strong>. You can use the PHP <strong>array_unique()</strong> function and PHP <strong>array_merge()</strong> function together to merge two arrays into one array without duplicate values in PHP.</p>
<h2>Merge two arrays</h2>
<p>You can use PHP <strong>array_merge</strong> function for merging both arrays into one array. it&#8217;s giving output like this.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$array1 = array(&quot;yellow&quot;, &quot;red&quot;, &quot;green&quot;, &quot;orange&quot;, &quot;purple&quot;);
$array2 = array(&quot;pink&quot;, &quot;brown&quot;, &quot;green&quot;, &quot;orange&quot;, &quot;red&quot;);
$array  = array_merge($array1, $array2);
print_r($array);
?&gt;
</pre>
<pre class="brush: php; title: ; notranslate">
Array
(
    &#x5B;0] =&gt; yellow
    &#x5B;1] =&gt; red
    &#x5B;2] =&gt; green
    &#x5B;3] =&gt; orange
    &#x5B;4] =&gt; purple
    &#x5B;5] =&gt; pink
    &#x5B;6] =&gt; brown
    &#x5B;7] =&gt; green
    &#x5B;8] =&gt; orange
    &#x5B;9] =&gt; red
)
</pre>
<p>In above output you can see there are many duplicate entries But we want to remove these duplicate entries before merging both array.</p>
<h2>Merge two arrays without duplicate values in PHP</h2>
<p>Now we will use <a href="https://www.thecodedeveloper.com/function-array_unique/" rel="noopener" target="_blank">array_unique()</a> and <a href="https://www.thecodedeveloper.com/merge-two-or-more-arrays-into-one-array/" rel="noopener" target="_blank">array_merge()</a> both PHP function together to merge two arrays and remove duplicate values like in below example:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$array1 = array(&quot;yellow&quot;, &quot;red&quot;, &quot;green&quot;, &quot;orange&quot;, &quot;purple&quot;);
$array2 = array(&quot;pink&quot;, &quot;brown&quot;, &quot;green&quot;, &quot;orange&quot;, &quot;red&quot;);
$array = array_unique(array_merge($array1, $array2));
print_r($array);
?&gt;
</pre>
<h5>The above example will output:</h5>
<pre class="brush: php; title: ; notranslate">
Array
(
    &#x5B;0] =&gt; yellow
    &#x5B;1] =&gt; red
    &#x5B;2] =&gt; green
    &#x5B;3] =&gt; orange
    &#x5B;4] =&gt; purple
    &#x5B;5] =&gt; pink
    &#x5B;6] =&gt; brown
)
</pre>
<p>In above output you can see we merged both arrays without duplicate values that&#8217;s what we want.</p>
<p>The post <a href="https://www.thecodedeveloper.com/merge-two-arrays-without-duplicate-values-in-php/">How to merge two arrays without duplicate values in PHP?</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/merge-two-arrays-without-duplicate-values-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Remove Empty Array Elements and Reindex In PHP</title>
		<link>https://www.thecodedeveloper.com/remove-empty-array-elements-and-reindex/</link>
					<comments>https://www.thecodedeveloper.com/remove-empty-array-elements-and-reindex/#respond</comments>
		
		<dc:creator><![CDATA[Vikas Kumar]]></dc:creator>
		<pubDate>Sun, 21 Oct 2018 17:39:23 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array Function]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=3540</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="1020" height="620" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Remove Empty Array Elements and Reindex from an array in PHP" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php.png 1020w, https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php-442x269.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php-768x467.png 768w" sizes="auto, (max-width: 1020px) 100vw, 1020px" /></div>
<p>In this article you will learn how to remove empty array elements and reindex from an array in PHP. You can easily do it after use array_values() and array_filter() function together to remove empty array elements and reindex from an array in PHP. array_filter() function The PHP array_filter() function remove empty array elements or values [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/remove-empty-array-elements-and-reindex/">Remove Empty Array Elements and Reindex In PHP</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="1020" height="620" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Remove Empty Array Elements and Reindex from an array in PHP" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php.png 1020w, https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php-442x269.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/10/remove-empty-array-elements-and-reindex-in-php-768x467.png 768w" sizes="auto, (max-width: 1020px) 100vw, 1020px" /></div><p>In this article you will learn how to <strong>remove empty array elements and reindex</strong> from an array in PHP. You can easily do it after use <strong>array_values()</strong> and <strong>array_filter()</strong> function together to <a href="https://www.thecodedeveloper.com/remove-empty-array-elements-in-php/">remove empty array elements</a> and reindex from an array in PHP.</p>
<h4 class="sitemaincolor">array_filter() function</h4>
<p>The PHP <strong>array_filter()</strong> function remove empty array elements or values from an array in PHP. This will also remove blank, null, false, 0 (zero) values.</p>
<h4 class="sitemaincolor">array_values() function</h4>
<p>The PHP <strong>array_values()</strong> function returns an array containing all the values of an array. The returned array will have numeric keys, starting at 0 and increase by 1.</p>
<h2>Remove Empty Array Elements and Reindex In PHP</h2>
<p>First let’s see the $stack array output :</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$stack = array(&quot;PHP&quot;, &quot;HTML&quot;, &quot;CSS&quot;, &quot;&quot;, &quot;JavaScript&quot;, null, 0);
print_r($stack);
?&gt;
</pre>
<p><strong>Output:</strong></p>
<pre class="brush: php; title: ; notranslate">
Array
(
    &#x5B;0] =&gt; PHP
    &#x5B;1] =&gt; HTML
    &#x5B;2] =&gt; CSS
    &#x5B;3] =&gt; 
    &#x5B;4] =&gt; JavaScript
    &#x5B;5] =&gt; 
    &#x5B;6] =&gt; 0
)
</pre>
<p>In above output we want to remove blank, null, 0 (zero) values and then reindex array elements. Now we will use array_values() and array_filter() function together like in below example:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$stack = array(&quot;PHP&quot;, &quot;HTML&quot;, &quot;CSS&quot;, &quot;&quot;, &quot;JavaScript&quot;, null, 0);
print_r(array_values(array_filter($stack)));
?&gt;
</pre>
<p><strong>Output:</strong></p>
<pre class="brush: php; title: ; notranslate">
Array
(
    &#x5B;0] =&gt; PHP
    &#x5B;1] =&gt; HTML
    &#x5B;2] =&gt; CSS
    &#x5B;3] =&gt; JavaScript
)
</pre>
<p>The post <a href="https://www.thecodedeveloper.com/remove-empty-array-elements-and-reindex/">Remove Empty Array Elements and Reindex In PHP</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/remove-empty-array-elements-and-reindex/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to get the first element of an array in PHP?</title>
		<link>https://www.thecodedeveloper.com/get-the-first-element-of-an-array-in-php/</link>
					<comments>https://www.thecodedeveloper.com/get-the-first-element-of-an-array-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Aastha Tyagi]]></dc:creator>
		<pubDate>Fri, 21 Sep 2018 18:56:22 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array Function]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=3346</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="970" height="470" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="How To Get The First Element Of An Array In PHP" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array.png 970w, https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array-442x214.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array-768x372.png 768w" sizes="auto, (max-width: 970px) 100vw, 970px" /></div>
<p>In this article we will discuss how to get the first element of an array in PHP. There are many ways to get the first element of an array in PHP. Get the first element of an array in PHP We are using several method like direct accessing the 0th index, foreach loop, reset() function, [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/get-the-first-element-of-an-array-in-php/">How to get the first element of an array in PHP?</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="970" height="470" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="How To Get The First Element Of An Array In PHP" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array.png 970w, https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array-442x214.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/09/get-the-first-element-of-an-array-768x372.png 768w" sizes="auto, (max-width: 970px) 100vw, 970px" /></div><p>In this article we will discuss <strong>how to get the first element of an array</strong> in PHP. There are many ways to <strong>get the first element of an array</strong> in PHP.</p>
<h2>Get the first element of an array in PHP</h2>
<p>We are using several method like direct accessing the 0th index, foreach loop, reset() function, array_shift() function, array_slice() function and array_values() to get the first element of an array.</p>
<h3 class="h3heading">Method #1 By direct accessing the 0th index:</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$stack_array = array( 'code', 'developer','programming', 'blog');
echo $stack_array&#x5B;0];
?&gt;
</pre>
<h4>The above example will output:</h4>
<pre class="brush: php; title: ; notranslate">
code
</pre>
<h3 class="h3heading">Method #2 Using foreach loop</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$stack_array = array( 'code', 'developer','programming', 'blog');

$max_loop    = 1; //this is the desired value of looping
$count       = 0; //first we set the count to be zero
foreach ($stack_array as $key =&gt; $value) {
    echo $value;
    $count++; //increase the value of the count by 1
    if ($count == $max_loop) { //break the loop is count is equal to the max_loop
        break;
    }
}
?&gt;
</pre>
<h4>The above example will output:</h4>
<pre class="brush: php; title: ; notranslate">
code
</pre>
<h3 class="h3heading">Method #3 Using reset() function</h3>
<p>The <strong>reset()</strong> function moves the internal pointer to the first element of the array and returns the value of the first array element.</p>
<h3>Syntax</h3>
<p>reset(array)</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php 
$stack_array = array( 'code', 'developer','programming', 'blog');
echo reset($stack_array);
?&gt;
</pre>
<h4>The above example will output:</h4>
<pre class="brush: php; title: ; notranslate">
code
</pre>
<h3 class="h3heading">Method #4 Using array_shift() function</h3>
<p>The <strong>array_shift()</strong> function removes the first element from an array, and returns the value of the removed element.</p>
<h3>Syntax</h3>
<p>array_shift(array)</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$stack_array = array( 'code', 'developer','programming', 'blog');
$first_element = array_shift($stack_array);
echo $first_element;
?&gt;
</pre>
<h4>The above example will output:</h4>
<pre class="brush: php; title: ; notranslate">
code
</pre>
<h3 class="h3heading">Method #5 Using array_slice() function</h3>
<p>The <strong>array_slice()</strong> function returns the sequence of elements from the array as specified by the offset and length parameters.</p>
<h3>Syntax</h3>
<p>array_slice(array,start,length,preserve)</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php 
$stack_array = array( 'code', 'developer','programming', 'blog');
$first_element = array_slice($stack_array, 0, 1);
echo $first_element&#x5B;0];
?&gt;
</pre>
<h4>The above example will output:</h4>
<pre class="brush: php; title: ; notranslate">
code
</pre>
<h3 class="h3heading">Method #6 Using array_values() function</h3>
<p>The <strong>array_values()</strong> function returns an array containing all the values of an array. The returned array will have numeric keys, starting at 0 and increase by 1.</p>
<h3>Syntax</h3>
<p>array_values(array)</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php 
$stack_array = array( 'code', 'developer','programming', 'blog');
$first_element = array_values($stack_array);
echo $first_element&#x5B;0];
?&gt;
</pre>
<h4>The above example will output:</h4>
<pre class="brush: php; title: ; notranslate">
code
</pre>
<p>The post <a href="https://www.thecodedeveloper.com/get-the-first-element-of-an-array-in-php/">How to get the first element of an array in PHP?</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/get-the-first-element-of-an-array-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
