Skip to content

Instantly share code, notes, and snippets.

View tihoho's full-sized avatar
❤️
Hey everyone!

Alex T tihoho

❤️
Hey everyone!
View GitHub Profile
<?php
session_start();
$count = 1;
if(isset($_SESSION['counter'])) {
$count = intval($_SESSION['counter']);
$_SESSION['counter']++;
<?php
function matrix($x = 3, $y = 3) {
$_matrix = [];
for($_x = 0; $_x < $x; $_x++) {
for($_y = 0; $_y < $y; $_y++) {
$_matrix[$_x][$_y] = mt_rand(1,5);
}
}
return $_matrix;
@tihoho
tihoho / fewWords.php
Created June 8, 2017 13:46
How to get a few words from the string on PHP
<?php
function fewWords($str, $limit) {
return rtrim(implode(' ', array_slice(explode(' ', $str), 0, $limit)), ',-');
}
// Example:
$str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt';