Tag Archives: PHP

PHP Arrays

Arrays are sets of data; can be defined in a PHP Script. Arrays can contain other arrays inside them without any restriction, hence building multidimensional arrays. Arrays can be referred to as tables or hashes.

You can create Arrays in two different ways. The first involves using the function array. The second involves using square brackets.

First is The Array Function Method

In the array function method you create a array in the scheme of:

$foo = bar()

For example, to set the array up to make the keys sequential numbers (Example: “0, 1, 2, 3”), use:

$foobar = array($foo, $bar);

This would produce the array as follows:

$foobar[0] = $foo
$foobar[1] = $bar

It is also possible to define the key value:

$foobar = array(‘foo’ => $foo, ‘bar’ => $bar);

This would set the array as follows:

$foobar[‘foo’] = $foo
$foobar[‘bar’] = $bar

And,

Second is The Square Brackets Method

The square brackets method allows you to set up by directly setting the values.

For example:

To make $foobar[1] = $foo, what you should do is:

$foobar[1] = $foo;

The same applies for setting up the key value:

$foobar[‘foo’] = $foo;

Other Array Lessons:

Embedding RSS Feed In Your WordPress Posts And Pages

Open Your themes function.php and add the following code at the bottom:

include_once(ABSPATH.WPINC.’/rss.php’);

function readRss($atts) {
extract(shortcode_atts(array(
“feed” => ‘http://‘,
“num” => ‘1’,
), $atts));

return wp_rss($feed, $num);
}

add_shortcode(‘rss’, ‘readRss’);

Save function.php and whenever you need to embed RSS in any of your post or page write the following short code inside your post:

[ rss feed=”https://sangkrit.net/feed” num=”5″ ]

In the above give short code replace https://sangkrit.net/feed with your feed address and in num=5 replace 5 with the number of posts you like to show.

Note: Remember there is no space between [ and rss feed and num=”5″  and  so after you copy the short code; check the space, remove it (if there is some space) and then publish it.