Pascal's triangle in PHP
These conditions can be simplified:


if($row==1 and $pos==1) // for first row.
{
    return 1;
}
else if($pos==0)    // for left most row element that doesn't exist.
{
    return 0;
}
else if($pos&gt;$row)  // for right most row element that doesn't exist.
{
    return 0;
}



To this:

if ($pos == 1 or $row == $pos)
{
    return 1;
}


Coding style

The expressions are too packed.
It would be better to add more spaces:


around operators
after semicolons
after commas in parameter lists
before opening ( of if conditions and for loops


So instead of this:


for($i=1;$i&lt;=$rows_to_generate;$i++)
{
    for($j=1;$j&lt;=$i;$j++)
    {
        echo $storage[$i][$j]=get_elem($i,$j);  // generate
        if($i!=$j)



This is easier to read:

for ($i = 1; $i &lt;= $rows_to_generate; $i++)
{
    for ($j = 1; $j &lt;= $i; $j++)
    {
        echo $storage[$i][$j] = get_elem($i, $j);  // generate
        if ($i != $j)