Creating functions in php

Post Reply
Nwobueze
Site Admin
Posts: 27
Joined: Wed Oct 03, 2018 1:15 am

Creating functions in php

Post by Nwobueze » Thu Jan 03, 2019 5:31 pm

php functions can be created using the key keyword 'function'

The syntax for creating functions

Code: Select all

<?php 
function function_name (parameter1, parameter2, ...) {
    //code to do some task
}

Chiomy
Posts: 17
Joined: Wed Oct 03, 2018 1:37 pm

Re: Creating functions in php

Post by Chiomy » Wed Jan 09, 2019 9:13 pm

Can some one put an array as a parameter in a function?

jesse smallz
Posts: 2
Joined: Mon Oct 08, 2018 7:52 pm

Re: Creating functions in php

Post by jesse smallz » Wed Jan 09, 2019 10:13 pm

Example of function for querying a database.

Code: Select all

<?php
	function query($pdo, $sql) {
		$query = $pdo->prepare($sql);
		$query->execute();
		return $query;
	}
?>
:D

Chiomy
Posts: 17
Joined: Wed Oct 03, 2018 1:37 pm

Re: Creating functions in php

Post by Chiomy » Sun Jan 20, 2019 10:32 am

Database connection need to be made first before querying can be done

Post Reply